Documentation: Chrome Scripting API
A promise-based wrapper for the Chrome scripting API to inject scripts and styles, and manage content scripts.
- executeScript(injection)
- getRegisteredContentScripts(filter?)
- insertCss(injection)
- registerContentScripts(scripts)
- removeCss(injection)
- unregisterContentScripts(filter?)
- updateContentScripts(scripts)
- isAvailableScripting()
executeScript<T = any>(
injection: chrome.scripting.ScriptInjection<any, T>
): Promise<chrome.scripting.InjectionResult<chrome.scripting.Awaited<T>>[]>
Executes a script in the specified target and returns the injection results.
getRegisteredContentScripts(
filter?: chrome.scripting.ContentScriptFilter
): Promise<chrome.scripting.RegisteredContentScript[]>
Retrieves registered content scripts, optionally filtered by criteria.
insertCss(injection: chrome.scripting.CSSInjection): Promise<void>
Injects CSS into specified target pages.
registerContentScripts(
scripts: chrome.scripting.RegisteredContentScript[]
): Promise<void>
Registers one or more content scripts programmatically.
removeCss(injection: chrome.scripting.CSSInjection): Promise<void>
Removes previously injected CSS from specified target pages.
unregisterContentScripts(
filter?: chrome.scripting.ContentScriptFilter
): Promise<void>
Unregisters content scripts matching the given filter.
updateContentScripts(
scripts: chrome.scripting.RegisteredContentScript[]
): Promise<void>
Updates existing content scripts with new definitions.
isAvailableScripting(): booleanReturns true when the scripting namespace is present on the API selected by browser() in the current context.
Returns false if the namespace or WebExtension environment is absent, or if accessing it throws.
The check is synchronous, does not log, and reads the current API on every call without caching.
It checks namespace presence only; it does not guarantee individual methods, permissions, or a successful operation.
import {isAvailableScripting} from "@addon-core/browser";
if (isAvailableScripting()) {
// The namespace is present; handle operation-specific failures when using it.
}