The Message API is the internal RPC layer that lets injected content scripts call functions implemented in the background (service worker) context, and vice versa. When you callDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/zotero/zotero-connectors/llms.txt
Use this file to discover all available pages before exploring further.
Zotero.Translators.get(...) from a page-injected script, the actual work runs in the background; the messaging layer serializes arguments, routes the call, awaits the result, and deserializes the response — all transparently. You would interact with the MESSAGES registry directly only when extending the connector with a new cross-context call, adding serialization hooks for a custom type, or debugging an unexpected message boundary failure.
The constant
MESSAGE_SEPARATOR is defined as ".". Message names are therefore formed as NAMESPACE.METHOD (e.g., Translators.get, Connector.callMethod). In Chrome/Chromium, messages are sent as [messageName, args] arrays through browser.runtime.onMessage; in Safari, the same namespace/method structure is used but transport is handled by safari/messaging_global.js.MESSAGES Registry Structure
Each entry in theMESSAGES object lives at MESSAGES[NAMESPACE][METHOD]. The value of each method entry controls messaging behavior:
| Value | Meaning |
|---|---|
true | The call is made and a response is expected and returned to the caller. |
false | Fire-and-forget — no response is awaited or returned. |
| Object | Advanced configuration with optional background and inject hook sub-objects (see below). |
Hook Object Shape
When a method value is an object but
response is not explicitly set to false, the call still returns a response. Setting response: false on an object entry makes it fire-and-forget even when hooks are configured (see Debug.log).Namespaces
Translators
Translators
Manages translator lookup and delivery from the background to injected scripts. Translators are heavy objects; hooks serialize them to plain objects crossing the boundary and reconstruct
Zotero.Translator instances on the inject side.| Method | Value | Notes |
|---|---|---|
updateFromRemote | true | Triggers a remote translator update; returns when complete. |
get | Object | Returns a single translator. |
getAllForType | Object | Returns all translators matching a type. |
getWebTranslatorsForLocation | Object | Returns web translators and proxies for a URL. |
getCodeForTranslator | Object | Returns translator code; inject side strips to translatorID before sending. |
get hooks:background.preSend— callsZotero.Translators.serialize(translators, TRANSLATOR_PASSING_PROPERTIES)before the response is sentinject.postReceive— reconstructs a singlenew Zotero.Translator(translator)from the plain object
getAllForType hooks:background.preSend— serializes the translators array withTRANSLATOR_PASSING_PROPERTIESinject.postReceive— maps each element tonew Zotero.Translator(translator)
getWebTranslatorsForLocation hooks:background.preSend— serializesdata[0](translators array) and passes throughdata[1](proxies)inject.postReceive— deserializesdata[0]toZotero.Translatorobjects anddata[1]tonew Zotero.Proxyobjects, returning[translators, proxies]
getCodeForTranslator hooks:inject.preSend— extracts only{ translatorID: translator.translatorID }from the full translator argument, reducing payload sizebackground.postReceive— callsZotero.Translators.getWithoutCode(translatorInfo.translatorID)and returns it as the first argument
OffscreenManager
OffscreenManager
Relay for the Manifest V3 offscreen document, which runs translator sandboxes outside the service worker.
| Method | Value | Notes |
|---|---|---|
sendMessage | true | Forwards a message to the offscreen document; returns the response. |
Debug
Debug
Debug logging and storage control across the background/inject boundary.
| Method | Value | Notes |
|---|---|---|
get | true | Retrieves the current debug log contents. |
bgInit | false | Signals background initialization; fire-and-forget. |
clear | false | Clears stored debug output; fire-and-forget. |
log | Object | Logs a debug message; fire-and-forget (response: false). |
setStore | false | Enables or disables debug log storage; fire-and-forget. |
log configuration:response: false— fire-and-forget despite being an object entrybackground.minArgs: 4— the args array is padded to at least 4 elements before the background function is invoked
Connector
Connector
Methods that communicate with (or about) the Zotero desktop client HTTP server.
| Method | Value | Notes |
|---|---|---|
checkIsOnline | true | Pings Zotero desktop; returns boolean. |
callMethod | true | Executes an HTTP RPC call to the Zotero connector server. |
callMethodWithCookies | true | Like callMethod but first collects and attaches browser cookies. |
saveSingleFile | Object | Saves a SingleFile snapshot; Chromium chunking applied. |
getClientVersion | true | Returns the Zotero desktop client version string (from ping). |
reportActiveURL | false | Reports the currently active tab URL to Zotero; fire-and-forget. |
getPref | true | Returns a named connector preference value from the cached prefs object. |
saveSingleFile hooks (Chromium only):inject.preSend— callsZotero.Messaging.sendAsChunks(args[1].snapshotContent)and replaces the content with the chunk ID, avoiding Chrome’s message size limitbackground.postReceive— callsZotero.Messaging.getChunkedPayload(args[1].snapshotContent)to reassemble the chunked payload before passing to the background function
The chunking path in
saveSingleFile is active only when Zotero.isChromium is true. On Firefox and Safari the snapshot content is passed directly.Connector_Browser
Connector_Browser
Browser-side UI and tab management calls, invoked from background to injected scripts.
| Method | Value | Notes |
|---|---|---|
onSelect | true | Notifies inject of a library/collection selection. |
onPageLoad | false | Fires on page load; fire-and-forget. |
onTranslators | Object | Delivers available translators for the current page. |
onZoteroButtonElementClick | true | Handles toolbar button click forwarding. |
injectScripts | true | Requests dynamic script injection into the tab. |
injectSingleFile | true | Requests SingleFile script injection. |
isIncognito | true | Returns whether the current tab is in a private/incognito window. |
isTabFocused | true | Returns whether the tab is currently focused. |
newerVersionRequiredPrompt | true | Displays the “update Zotero” prompt; returns user choice. |
openTab | false | Opens a new tab; fire-and-forget. |
openConfigEditor | false | Opens the advanced config editor; fire-and-forget. |
openPreferences | false | Opens the preferences page; fire-and-forget. |
bringToFront | true | Brings a window to the foreground. |
onTranslators hooks:inject.preSend— serializes the translators array witht.serialize(TRANSLATOR_PASSING_PROPERTIES)before sending to the background, keeping only the fields needed across the boundary
Zotero.isSafari is true):| Method | Value | Notes |
|---|---|---|
onPDFFrame | false | Signals detection of a PDF in a frame; fire-and-forget. |
onPerformCommand | false | Handles a Safari toolbar command; fire-and-forget. |
onTabFocus | false | Notifies on tab focus events; fire-and-forget. |
onTabData | true | Requests tab metadata from the native layer. |
getExtensionVersion | true | Returns the Safari extension version string. |
Connector_Debug
Connector_Debug
Exposes debug state queries from the injected/UI context to the background, where
Zotero.Debug lives.| Method | Value | Notes |
|---|---|---|
storing | true | Returns true if debug output is currently being stored. |
get | true | Returns the full debug log as a string. |
count | true | Returns the number of lines currently in the debug log. |
ItemSaver
ItemSaver
Handles saving items and attachments, both to Zotero desktop and to the Zotero web API server.
| Method | Value | Notes |
|---|---|---|
saveAttachmentToZotero | true | Saves an attachment to the connected Zotero desktop. |
saveStandaloneAttachmentToZotero | true | Saves a standalone attachment (e.g., PDF) directly to Zotero desktop. |
saveAttachmentToServer | Object | Saves an HTML attachment to the Zotero web server; Chromium chunking applied. |
saveAttachmentToServer hooks (Chromium only):inject.preSend— fortext/htmlattachments whosedatais a string, callsZotero.Messaging.sendAsChunks(attachment.data)and replacesdatawith the chunk IDbackground.postReceive— reassembles the chunked HTML withZotero.Messaging.getChunkedPayload(attachment.data), then appends the currenttabobject as the last argument before calling the background function
Errors
Errors
Error collection and system information retrieval from the background.
| Method | Value | Notes |
|---|---|---|
log | false | Logs an error object; fire-and-forget. |
getErrors | true | Returns the array of logged errors. |
getSystemInfo | true | Returns a JSON string of system information (browser, OS, extension version, etc.). |
Messaging
Messaging
Internal messaging infrastructure methods, used by the messaging layer itself.
| Method | Value | Notes |
|---|---|---|
sendMessage | Object | Sends a message to a specific tab/frame; background injects tab and frameId. |
receiveChunk | true | Stores an incoming chunk of a large chunked payload for later reassembly. |
sendMessage hooks:background.postReceive— ensuresargs[2]is the current tab object (appending it if not present), and ensuresargs[3]is the frameId (defaulting to0for the top frame)
API
API
Zotero Web API OAuth authorization and item/attachment operations.
| Method | Value | Notes |
|---|---|---|
authorize | true | Initiates the OAuth authorization flow; resolves with user info on success. |
onAuthorizationComplete | false | Called when the OAuth callback page is reached; fire-and-forget. |
clearCredentials | false | Removes stored OAuth credentials; fire-and-forget. |
getUserInfo | true | Returns stored OAuth user info (auth-token_secret, auth-userID, auth-username) or null. |
run | true | Runs an API operation. |
uploadAttachment | Object | Uploads a binary attachment; ArrayBuffer is packed/unpacked across the boundary. |
uploadAttachment hooks:inject.preSend— callspackArrayBuffer(args[0].data)to convert theArrayBufferto a serializable form (base64 on Safari, byte array on MV3, blob URL on MV2 Chromium)background.postReceive— callsunpackArrayBuffer(args[0].data)to restore the originalArrayBuffer
Zotero.isSafari is true):| Method | Value | Notes |
|---|---|---|
createItem | true | Creates a Zotero web API item directly from the background (Safari only). |
uploadAttachment | false | On Safari, attachment upload is fire-and-forget (handled natively). |
GoogleDocs_API
GoogleDocs_API
Google Docs citation integration, bridging the connector injected into
docs.google.com and the background Apps Script runner.| Method | Value | Notes |
|---|---|---|
onAuthComplete | false | Signals completion of Google OAuth; fire-and-forget. |
run | Object | Runs a Google Apps Script function. |
getDocument | true | Fetches the current Google Doc structure. |
batchUpdateDocument | true | Applies a batch of updates to the Google Doc. |
run configuration:background.minArgs: 3— args array is padded to at least 3 elements before the background function is called
Prefs
Prefs
Preference read/write operations from injected scripts, backed by
browser.storage.local in the background.| Method | Value | Notes |
|---|---|---|
set | false | Sets a preference value; fire-and-forget. |
getAll | true | Returns all stored preferences as an object. |
getDefault | true | Returns the default value for a preference key. |
getAsync | true | Returns a preference value (or object of values for an array of keys). |
removeAllCachedTranslators | true | Clears all cached translator code from storage; returns when complete. |
clear | false | Removes a preference key (or array of keys); fire-and-forget. |
Proxies
Proxies
Proxy configuration management from the preferences UI to the background.
| Method | Value | Notes |
|---|---|---|
loadPrefs | false | Reloads proxy preferences in the background; fire-and-forget. |
validate | true | Validates a proxy configuration object; returns an error tuple or null. |
save | false | Persists a proxy configuration; fire-and-forget. |
remove | false | Removes a proxy configuration; fire-and-forget. |
toggleRedirectLoopPrevention | false | Enables or disables redirect loop prevention; fire-and-forget. |
WebRequestIntercept
WebRequestIntercept
Controls browser web request interception for user-agent spoofing.
| Method | Value | Notes |
|---|---|---|
replaceUserAgent | true | Sets a custom User-Agent string on intercepted requests; returns the previous value. |
ContentTypeHandler
ContentTypeHandler
Controls interception of importable file types (BibTeX, RIS, etc.) for direct import into Zotero.
| Method | Value | Notes |
|---|---|---|
handleImportableStyle | true | Handles detection of a CSS/style file for import. |
handleImportableContent | true | Handles detection of a BibTeX/RIS/Refer file for import. |
enable | false | Enables content-type interception globally; fire-and-forget. |
disable | false | Disables content-type interception globally; fire-and-forget. |
COHTTP
COHTTP
Cross-origin HTTP — proxies XHR requests through the background to work around content-script network restrictions. The background performs the actual request; the inject side receives a reconstructed XHR-like object.
If
| Method | Value | Notes |
|---|---|---|
request | Object | Performs an XHR in the background and returns a reconstructed response object. |
request hooks:background.preSend — strips the non-serializable responseXML property and builds a plain result object:response is an ArrayBuffer, it is packed via packArrayBuffer before sending.inject.postReceive — reconstructs the XHR-like interface on the received object:- Attaches
getAllResponseHeaders()andgetResponseHeader(name)methods backed by theresponseHeadersstring - Detects the packed format (Safari base64, MV3 byte array, MV2 blob URL) and calls
unpackArrayBufferif needed; otherwise assignsresponseText = response
i18n (Safari only)
i18n (Safari only)
Internationalization string retrieval, added only when
Zotero.isSafari is true.| Method | Value | Notes |
|---|---|---|
getStrings | true | Returns localized string map for the current locale. |
Adding a New Message
Register the method in MESSAGES
Open
src/common/messages.js and add your method to the appropriate namespace (or create a new namespace):Implement the handler in the background
In your background module, implement
Zotero.MyNamespace.myMethod. The messaging layer automatically routes MyNamespace.myMethod calls to Zotero.MyNamespace.myMethod(…args, tab, frameId).