userScripts API
Hint
The userScripts API is inherited from Firefox, and its primary documentation is maintained by Mozilla at MDN. Thunderbird implements only the subset of functions, events, and types listed here. The MDN pages may provide further details and examples, but they may also reference features that are not supported in Thunderbird.
Note
Available for use with Manifest V3 only.
Note
An incompatible version of this API is available for Manifest V2. See userScripts (Legacy).
Manifest file properties
user_scripts
api_script
Permissions
The following permissions influence the behavior of the API. Depending on which permissions are requested, additional methods might be available, or certain data may be included in responses.
Hint
Request permissions only when needed. Unnecessary requests may result in rejection during ATN review.
userScripts
Allow unverified third-party scripts to access your data.
Functions
register(userScriptOptions)
– [Added in TB 136]
Register a user script programmatically given its UserScriptOptions, and resolves to an object with the unregister() function
Note
An incompatible version of this function is available for Manifest V2. See userScripts (Legacy).
Return type (Promise)
_returns
Required permissions
Events
onBeforeScript
Event called when a new userScript global has been created
Parameters for onBeforeScript.addListener(listener)
listener(userScript)
A function that will be called when this event occurs.
Parameters passed to the listener function
userScript
defineGlobals
Exports all the properties of a given plain object as userScript globals
export
Convert a given value to make it accessible to the userScript code
global
The userScript global
metadata
The userScript metadata (as set in userScripts.register)
Required permissions
Types
ExtensionFileOrCode
Specify code, either by pointing to a file or by providing the code directly. Only one of the two is allowed.
object
file
A URL relative to the extension’s manifest.json file, and pointing to a JavaScript file to register.
or
object
code
A string of JavaScript code to register.
ExtensionURL
A path relative to the root of the extension.
string
MatchPattern
string
or
or
MatchPatternRestricted
Same as MatchPattern above, but excludes <all_urls>
string
or
string
MatchPatternUnestricted
Mostly unrestricted match patterns for privileged add-ons. This should technically be rejected for unprivileged add-ons, but, reasons. The MatchPattern class will still refuse privileged schemes for those extensions.
string
PlainJSONValue
A plain JSON value
null
or
number
or
string
or
boolean
or
array of PlainJSONValue
or
object
RunAt
– [Added in TB 45]
The soonest that the JavaScript or CSS will be injected into the tab.
UserScriptOptions
Details of a user script
object
js
The list of JS files to inject
matches
allFrames
If allFrames is true, implies that the JavaScript should be injected into all frames of current page. By default, it’s false and is only injected into the top frame.
cookieStoreId
limit the set of matched tabs to those that belong to the given cookie store id
excludeGlobs
excludeMatches
includeGlobs
matchAboutBlank
If matchAboutBlank is true, then the code is also injected in about:blank and about:srcdoc frames if your extension has access to its parent document. Code cannot be inserted in top-level about:-frames. By default it is false.
runAt
The soonest that the JavaScript will be injected into the tab. Defaults to “document_idle”.
scriptMetadata
An opaque user script metadata value