scripting

Inserts JavaScript and CSS into websites. This API offers two approaches to inserting content:

Note: This API is available in Manifest V3 or higher in Chrome and Firefox 101. In Safari and Firefox 102+, this API is also available in Manifest V2.

This API requires the "scripting" permission and host permission for the target in the tab into which JavaScript or CSS is injected.

Alternatively, you can get permission temporarily in the active tab and only in response to an explicit user action, by asking for the "activeTab" permission. However, the "scripting" permission is still required.

Types

scripting.ContentScriptFilter

Specifies the IDs of scripts to retrieve with scripting.getRegisteredContentScripts() or to unregister with scripting.unregisterContentScripts().

scripting.InjectionTarget

Details of an injection target.

scripting.RegisteredContentScript

Details of a content script to be registered or that is registered.

Functions

scripting.executeScript()

Injects JavaScript code into a page.

scripting.getRegisteredContentScripts()

Gets a list of registered content scripts.

scripting.insertCSS()

Injects CSS into a page.

scripting.registerContentScripts()

Registers a content script for future page loads.

scripting.removeCSS()

Removes CSS which was previously injected into a page by a scripting.insertCSS() call.

scripting.updateContentScripts()

Updates one or more content scripts already registered.

scripting.unregisterContentScripts()

Unregisters one or more content scripts.

Browser compatibility

BCD tables only load in the browser

Note: This API is based on Chromium's chrome.scripting API.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.