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(method?: ApiMethodName<typeof chrome.scripting>): booleanThe optional method is a native function name, for example isAvailableScripting("executeScript").
Import the public ApiMethodName type from @addon-core/browser for your own typed helpers.
This checks callable presence without invoking the method; permissions and argument support still require handling.
Returns 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.
Without an argument, it checks namespace presence only. Pass a native method name to also check that it is callable.
Neither form verifies permissions, argument support, or a successful operation. See method availability.
import {isAvailableScripting} from "@addon-core/browser";
if (isAvailableScripting()) {
// The namespace is present; handle operation-specific failures when using it.
}