• Stars
    star
    503
  • Rank 87,705 (Top 2 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 13 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Chrome, Firefox, Edge, and Safari extensions for Zotero

Zotero Connectors

Build Status

Building

  1. git clone --recursive https://github.com/zotero/zotero-connectors.git
  2. cd zotero-connectors
  3. npm install
  4. ./build.sh -d

The connectors are built in build/.

Running from the build directory

Chrome

  1. Go to chrome://extensions/
  2. Enable "Developer Mode".
  3. Click "Load unpacked extensionโ€ฆ" and select the build/browserExt directory.

Firefox

  1. Go to about:debugging
  2. Click "Load Temporary Add-on" and select the build/browserExt/manifest.json file.

OR

  1. Get and install the Mozilla web-ext tool
  2. cd to project root
  3. ./scripts/firefox/run_xpi

Safari

See https://github.com/zotero/safari-app-extension

Automatic rebuilding/reloading

Chrome on MacOS

  1. brew install chrome-cli
  2. npm install -g gulp
  3. cd to project root
  4. npm install
  5. build.sh -d
  6. gulp watch-chrome

As files are changed, the connectors will be rebuilt automatically and Chrome will reload the extension.

Firefox

  1. Get and install the Mozilla web-ext tool
  2. cd to project root
  3. npm install
  4. build.sh -d
  5. gulp watch
  6. ./scripts/firefox/run_xpi (in a different terminal window)

As files are changed, the connectors will be rebuilt automatically and Firefox will reload the extension.

Others

  1. cd to project root
  2. npm install
  3. build.sh -d
  4. gulp watch

As files are changed, the connectors will be rebuilt automatically. You will need to manually reload the extension in the browser being developed for.

Requirements for packaging extensions from the command line

Tests

To run tests locally, build the extension with the -d flag, and then run

$ ./test/run_tests -p c

Test files are located at src/common/test. See src/common/test/testSetup.js for test framework documentation

Developing

Zotero Connectors are built with standard tools, such as browser extension APIs, but the architecture is quite complex. This section is a short overview of some of the complexities, to make it more accessible for newcomers.

Technologies

Chrome/Firefox Browser Extension Framework

The functionality exposed on Chrome and Firefox is provided by the Chrome extension framework, which has also been adopted by Firefox. See Chrome Extension docs and Firefox Extension docs for more information.

Safari Extension Framework

For Safari specifics see https://github.com/zotero/safari-app-extension

Zotero Translator Framework

The Connectors share code with Zotero desktop application, to support translation. A basic understanding of how translation works or at least the handlers it exposes in Zotero will be highly useful in understanding the codebase.

Components

Saving resources to Zotero library is facilitated by two major components: the Zotero Connector running in the browser and either the Zotero client or zotero.org web api. The Zotero Connector itself is split into two components: code running on the webpage and a background process.

a) Injected scripts for individual webpages

Each webpage is injected (Chrome/Firefox/Safari) with a full Zotero translation framework. A Zotero.Translate.Web instance orchestrates running individual translators for detection and translation.

The translation framework shares some code with the Zotero codebase and provides custom classes concerning translator retrieval and item saving. These custom classes talk to the background process (b) of the Zotero Connector for functionality outside the translation framework, such as retrieving translator code and sending translated items either to Zotero (c) or zotero.org (d).

b) Background process

The Connector runs a background process (Chrome/Firefox/Safari) which works as a middle-layer between the translation framework running in inject scripts (a) and Zotero (c) or zotero.org (d).

The background process maintains a cache of translators and performs the initial translator detection using URL matching. Translators whose target regexp matches the URL of a given webpage are then further tested by running detectWeb() in injected scripts. A list of translators and their code is fetched either from Zotero (c) or zotero.org (d).

The background process is also responsible for updating the extension UI, kicking off translations, storing and retrieving connector preferences and sending translated items to Zotero or zotero.org. Browser specific scripts are available for BrowserExt and Safari.

c) Connector server in Zotero

When Zotero is open it runs a connector HTTP server on port 23119. The HTTP server API accommodates interactions between the Connectors and Zotero client. Calls to Zotero.Connector.callMethod(endpoint) in this codebase are translated to HTTP requests to the connector server.

Note that Zotero cannot interact with the connectors on its own accord. All communication is Connector initiated.

d) zotero.org API

When Zotero is not available item saving falls back to using zotero.org API. The interactions with zotero.org API are defined in api.js

Message passing

The only way for the background extension process and injected scripts to communicate is using the message passing protocol provided by the browsers (Chrome/Firefox/Safari). Injected scripts often need to communicate to background scripts. To simplify these interactions, calls to functions in background scripts are monkey-patched in injected scripts. These calls are asynchronous and if a return value is required, it is provided either to a callback function as the last argument of the call or as a resolving value of a promise returned.

messages.js contains the list of the monkey-patched methods. If the method value is false no response is expected, otherwise the calls provide a response. An optional pre-send processing on the background end and post-receive processing on the injected end is possible to treat values that cannot be sent as-is via the messaging protocol.

The background process registers message listeners in messaging.js. Zotero.Messaging class also provides a way to send messages to injected scripts and add custom message listeners.

The injected scripts monkey-patch methods in messaging_injected.js(BrowserExt/Safari) Zotero.Messaging class also provides a way to send messages to the background process and add message listeners.

Build process

The build process combines files from the Zotero codebase, common files to all connectors and specific files for Chrome/Firefox/Safari connectors. At the moment the build process is awkward and uses a SH script and gulp procedures. This will be reconciled in the future to only use gulp.

  1. build.sh copies images and extension files
  2. gulp process-custom-files initiated by build.sh performs post-processing on copied files

Contact

If you have any questions about developing Zotero Connectors you can join the discussion in the zotero-dev mailing list.

More Repositories

1

zotero

Zotero is a free, easy-to-use tool to help you collect, organize, annotate, cite, and share your research sources.
JavaScript
9,904
star
2

translators

Zotero Translators
JavaScript
1,229
star
3

zotero-android

Zotero for Android
Kotlin
276
star
4

dataserver

Zotero Data Server
PHP
270
star
5

zotero-ios

Zotero for iOS
Swift
223
star
6

web-library

JavaScript
142
star
7

reader

PDF/EPUB/HTML reader for Zotero
JavaScript
121
star
8

translation-server

A Node.js-based server to run Zotero translators
JavaScript
121
star
9

zotero-standalone-build

Zotero client build utility
C++
120
star
10

citeproc-rs

CSL processor in Rust.
Rust
70
star
11

zoterobib

ZoteroBib is a free online bibliography generator from the makers of Zotero
JavaScript
68
star
12

zotero-libreoffice-integration

Zotero LibreOffice integration
Java
64
star
13

citeproc-js-server

Web service to generate citations and bibliographies using citeproc-js
JavaScript
60
star
14

zotero-bits

CSL-related community feedback for Zotero
56
star
15

make-it-red

Sample plugin for Zotero 7
JavaScript
47
star
16

zotero-word-for-windows-integration

Zotero Word for Windows integration
C++
46
star
17

zotero-schema

JSON representation of the Zotero data model
JavaScript
43
star
18

scaffold

Zotero translator creation IDE
Shell
38
star
19

translation-server-old

Server-side Zotero translation based on Mozilla xpcshell (deprecated)
JavaScript
35
star
20

publications

Easily display Zotero items on a webpage
JavaScript
32
star
21

zotero-google-docs-integration

JavaScript
32
star
22

note-editor

Note editor for Zotero
JavaScript
31
star
23

zotero-api-node

Zotero API client for Node.js
JavaScript
29
star
24

safari-app-extension

Swift
29
star
25

web-components

JS components used throughout zotero.org outside the web library
JavaScript
28
star
26

zotero-hello-world

Sample plugin for Zotero for Firefox
JavaScript
25
star
27

zotero-word-for-mac-integration

Zotero Word for Mac integration
Objective-C
23
star
28

pdf-worker

JavaScript
22
star
29

translate

Browser standalone zotero translator
JavaScript
16
star
30

cross-poppler

Compiles modified Poppler PDF tools for macOS, Windows and Linux
C++
15
star
31

styles-repo

Zotero styles page
PHP
13
star
32

zotero-build

Zotero client build scripts
Python
11
star
33

bundled-styles

CSL styles bundled with Zotero client
Shell
10
star
34

utilities

Zotero utility code
JavaScript
10
star
35

stream-server

Zotero Streaming API Server
JavaScript
9
star
36

cross-xpdf

C++
9
star
37

arkivo

JavaScript
8
star
38

epub.js

JavaScript
7
star
39

s3-full-text-indexer

JavaScript
5
star
40

full-text-indexer

Lambda functions to process full text from S3 and index in Elasticsearch
JavaScript
5
star
41

attachment-proxy

Allows online viewing of Zotero attachments
JavaScript
4
star
42

arkivo-sufia

A Zotero/Arkivo plugin to connect to Project Hydra services
JavaScript
3
star
43

provo

Zotero translator test automation
Shell
3
star
44

zfs-purge

Purge unused storage files from S3
JavaScript
3
star
45

eslint-config-zotero

ESLint shareable config for Zotero projects
JavaScript
3
star
46

markdown-translator-builder

Builds Markdown translator for Zotero notes export
JavaScript
3
star
47

client-downloads

Generate download links and update manifests for Zotero client
PHP
3
star
48

tinymce-clean-server

Node.js HTTP server to clean HTML using TinyMCE parsing/filtering logic
JavaScript
3
star
49

full-text-es-to-s3-migration

Script to migrate full-text content from Elasticsearch to S3
JavaScript
2
star
50

web-common

JavaScript
2
star
51

full-text-extractor

JavaScript
1
star