Docs
Web API
chrome.scripting
# chrome.scripting
On this page
Scripts and style sheets the extension puts into documents (src/page/ext_scripting.odin, ext_inject.odin; docs/extensions.md, section 3.6). A target is a tab and, in it, some frames or documents; each document must be one the extension has a host grant for, and none of Wren's own pages or another extension's. A script runs in the extension's isolated world of the document (ISOLATED), or in the page's own realm without any extension API (MAIN).
Gate: permission scripting; contexts: Background, Popup, Tab. Source: api/ext_scripting.widl.
# Methods and properties
Member Result Status Gate
executeScript(ScriptInjection injection)InjectionResult []host Runs files or a function in the target's documents. The answer lists each document's result.
insertCSS(CSSInjection injection)void host Adds a style sheet to the target's documents; scripts of the page do not see it in document.styleSheets.
removeCSS(CSSInjection injection)void host Removes a sheet insertCSS added with the same text or files.
registerContentScripts(RegisteredContentScript[] scripts)void host Content scripts matched against every document from now on, as the manifest's are.
getRegisteredContentScripts(optional ContentScriptFilter filter)RegisteredContentScript []host
unregisterContentScripts(optional ContentScriptFilter filter)void host No filter: every registered script.
updateContentScripts(RegisteredContentScript[] scripts)void host Changes registered scripts: what an entry gives replaces the registered script of its id.
# Types
# ExecutionWorld
A string: "ISOLATED", "MAIN". chrome.scripting.ExecutionWorld names them.
# StyleOrigin
A string: "AUTHOR", "USER". chrome.scripting.StyleOrigin names them.
# RunAt
A string: "document_start", "document_end", "document_idle". chrome.scripting.RunAt names them.
# InjectionTarget
Property Type
tabIdi64
frameIds (optional)i64[] Frame ids (0: the tab's top document). None: the top document, or every frame with allFrames.
documentIds (optional)string[]
allFrames (optional)bool
# ScriptInjection
Property Type
targetInjectionTarget
files (optional)string[] Files of the extension, run in order: the result is the last one's.
func (optional)string The source of a function (chrome.scripting sends func.toString()); it is called with args.
args (optional)any[]
world (optional)ExecutionWorld
injectImmediately (optional)bool Accepted: a script always runs as soon as the document exists.
# CSSInjection
# InjectionResult
The result of one document: a function's value (a promise's, once settled), as JSON; null for files and for the MAIN world.
Property Type
result (optional)any
frameIdi64
documentIdstring
# RegisteredContentScript
Property Type
idstring
matches (optional)string[]
excludeMatches (optional)string[]
js (optional)string[]
css (optional)string[]
allFrames (optional)bool
matchOriginAsFallback (optional)bool
runAt (optional)RunAt
world (optional)ExecutionWorld
persistAcrossSessions (optional)bool Accepted; the registered scripts last until the browser exits or the extension reloads.
# ContentScriptFilter
Property Type
ids (optional)string[]
Previous chrome.runtime
Next chrome.storage.local
Edit this page on GitHub