scripting
Inserts JavaScript and CSS into websites. This API offers two approaches to inserting content:
Inserts JavaScript and CSS into websites. This API offers two approaches to inserting content:
- scripting.executeScript(), scripting.insertCSS(), and scripting.removeCSS() that provide for one-off injections.
- scripting.registerContentScripts() that registers content scripts dynamically, which can then be retrieved with scripting.getRegisteredContentScripts() and unregistered with scripting.unregisterContentScripts().
[!NOTE] Chrome restricts this API to Manifest V3. Firefox and Safari support this API in Manifest V2 and V3.
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.ExecutionWorld
- : Specifies the execution environment of a script injected with scripting.executeScript() or registered with scripting.registerContentScripts().
- 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.
h2
Browser compatibility
[!NOTE] This API is based on Chromium's
chrome.scriptingAPI.