Wren

chrome.scripting

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

MemberResultStatusGate
executeScript(ScriptInjection injection)InjectionResult[]hostRuns files or a function in the target's documents. The answer lists each document's result.
insertCSS(CSSInjection injection)voidhostAdds a style sheet to the target's documents; scripts of the page do not see it in document.styleSheets.
removeCSS(CSSInjection injection)voidhostRemoves a sheet insertCSS added with the same text or files.
registerContentScripts(RegisteredContentScript[] scripts)voidhostContent scripts matched against every document from now on, as the manifest's are.
getRegisteredContentScripts(optional ContentScriptFilter filter)RegisteredContentScript[]host
unregisterContentScripts(optional ContentScriptFilter filter)voidhostNo filter: every registered script.
updateContentScripts(RegisteredContentScript[] scripts)voidhostChanges 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

PropertyType
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

PropertyType
targetInjectionTarget
files (optional)string[]Files of the extension, run in order: the result is the last one's.
func (optional)stringThe source of a function (chrome.scripting sends func.toString()); it is called with args.
args (optional)any[]
world (optional)ExecutionWorld
injectImmediately (optional)boolAccepted: a script always runs as soon as the document exists.

CSSInjection

PropertyType
targetInjectionTarget
css (optional)string
files (optional)string[]
origin (optional)StyleOrigin

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.

PropertyType
result (optional)any
frameIdi64
documentIdstring

RegisteredContentScript

PropertyType
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)boolAccepted; the registered scripts last until the browser exits or the extension reloads.

ContentScriptFilter

PropertyType
ids (optional)string[]

Edit this page on GitHub