Use the scripting API to execute script in different contexts.

Permissions: scripting

Not allowed in: Content scripts, Devtools pages

_UpdateContentScriptsScripts
ContentScriptFilter
CSSInjection
InjectionResult
InjectionTarget
RegisteredContentScript
ScriptInjection
_CSSInjectionOrigin
ExecutionWorld
executeScript
getRegisteredContentScripts
insertCSS
registerContentScripts
removeCSS
unregisterContentScripts
updateContentScripts
_CSSInjectionOrigin: "USER" | "AUTHOR"

The style origin for the injection. Defaults to 'AUTHOR'.

ExecutionWorld: "ISOLATED"

The JavaScript world for a script to execute within. We currently only support the 'ISOLATED' world.

  • Injects a script into a target context. The script will be run at document_idle.

    Parameters

    Returns Promise<InjectionResult[]>

  • Inserts a CSS stylesheet into a target context. If multiple frames are specified, unsuccessful injections are ignored.

    Parameters

    • injection: CSSInjection

      The details of the styles to insert.

    Returns Promise<void>

  • Registers one or more content scripts for this extension.

    Parameters

    • scripts: browser.scripting.RegisteredContentScript[]

      Contains a list of scripts to be registered. If there are errors during script parsing/file validation, or if the IDs specified already exist, then no scripts are registered.

    Returns Promise<void>

  • Removes a CSS stylesheet that was previously inserted by this extension from a target context.

    Parameters

    • injection: CSSInjection

      The details of the styles to remove. Note that the css, files, and origin properties must exactly match the stylesheet inserted through insertCSS. Attempting to remove a non-existent stylesheet is a no-op.

    Returns Promise<void>

  • Unregisters one or more content scripts for this extension.

    Parameters

    • Optionalfilter: ContentScriptFilter

      If specified, only unregisters dynamic content scripts which match the filter. Otherwise, all of the extension's dynamic content scripts are unregistered.

    Returns Promise<void>

  • Updates one or more content scripts for this extension.

    Parameters

    • scripts: _UpdateContentScriptsScripts[]

      Contains a list of scripts to be updated. If there are errors during script parsing/file validation, or if the IDs specified do not already exist, then no scripts are updated.

    Returns Promise<void>