contentScripts API

Functions

register(contentScriptOptions)

Register a content script programmatically

Parameters

contentScriptOptions

Types

RegisteredContentScript

An object that represents a content script registered programmatically

object

  • unregister() Unregister a content script registered programmatically

RegisteredContentScriptOptions

Details of a content script registered programmatically

object

matches

(array of contentScripts.MatchPattern)

[allFrames]

(boolean, optional)

If allFrames is true, implies that the JavaScript or CSS should be injected into all frames of current page. By default, it’s false and is only injected into the top frame.

[cookieStoreId]

(array of string or string, optional)

limit the set of matched tabs to those that belong to the given cookie store id

[css]

(array of ExtensionFileOrCode, optional)

The list of CSS files to inject

[excludeGlobs]

(array of string, optional)

[excludeMatches]

(array of contentScripts.MatchPattern, optional)

[includeGlobs]

(array of string, optional)

[js]

(array of ExtensionFileOrCode, optional)

The list of JS files to inject

[matchAboutBlank]

(boolean, optional)

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. Ignored if matchOriginAsFallback is specified. By default it is false.

[matchOriginAsFallback]

(boolean, optional)

If matchOriginAsFallback is true, then the code is also injected in about:, data:, blob: when their origin matches the pattern in ‘matches’, even if the actual document origin is opaque (due to the use of CSP sandbox or iframe sandbox). Match patterns in ‘matches’ must specify a wildcard path glob. By default it is false.

[runAt]

(RunAt, optional)

The soonest that the JavaScript or CSS will be injected into the tab. Defaults to “document_idle”.

[world]

(ExecutionWorld, optional)

The JavaScript world for a script to execute within. Defaults to “ISOLATED”.

External Types

The following types are not defined by this API, but by the underlying Mozilla WebExtension code base. They are included here, because there is no other public documentation available.

ExtensionFileOrCode

Specify code, either by pointing to a file or by providing the code directly. Only one of the two is allowed.

object

code

(string)

Some JavaScript code to register.

file

(string)

A URL starting at the extension’s manifest.json and pointing to a JavaScript file to register.