Skip to content

Latest commit

 

History

History
119 lines (80 loc) · 2.92 KB

scripting.md

File metadata and controls

119 lines (80 loc) · 2.92 KB

scripting

Documentation: Chrome Scripting API

A promise-based wrapper for the Chrome scripting API to inject scripts and styles, and manage content scripts.

Methods


executeScript

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

getRegisteredContentScripts(
  filter?: chrome.scripting.ContentScriptFilter
): Promise<chrome.scripting.RegisteredContentScript[]>

Retrieves registered content scripts, optionally filtered by criteria.

insertCss

insertCss(injection: chrome.scripting.CSSInjection): Promise<void>

Injects CSS into specified target pages.

registerContentScripts

registerContentScripts(
  scripts: chrome.scripting.RegisteredContentScript[]
): Promise<void>

Registers one or more content scripts programmatically.

removeCss

removeCss(injection: chrome.scripting.CSSInjection): Promise<void>

Removes previously injected CSS from specified target pages.

unregisterContentScripts

unregisterContentScripts(
  filter?: chrome.scripting.ContentScriptFilter
): Promise<void>

Unregisters content scripts matching the given filter.

updateContentScripts

updateContentScripts(
  scripts: chrome.scripting.RegisteredContentScript[]
): Promise<void>

Updates existing content scripts with new definitions.

isAvailableScripting

isAvailableScripting(): boolean

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. 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.
}