Skip to content

Commit

Permalink
Add docs for ExecutionWorld of scripting.executeScript API (#24316)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob--W committed Feb 14, 2023
1 parent d7b4ca7 commit 8939214
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ let results = await browser.scripting.executeScript(

- : An object describing the script to inject. It contains these properties:

- `args`
- `args` {{optional_inline}}
- : An array of arguments to carry into the function. This is only valid if the `func` parameter is specified. The arguments must be JSON-serializable.
- `files`
- `files` {{optional_inline}}
- : `array` of `string`. An array of path of the JS files to inject, relative to the extension's root directory. Exactly one of `files` and `func` must be specified.
- `func`
- `func` {{optional_inline}}
- : `function`. A JavaScript function to inject. This function is serialized and then deserialized for injection. This means that any bound parameters and execution context are lost. Exactly one of `files` and `func` must be specified.
- `injectImmediately` {{optional_inline}}
- : `boolean`. Whether the injection into the target is triggered as soon as possible, but not necessarily prior to page load.
- `target`
- : {{WebExtAPIRef("scripting.InjectionTarget")}}. Details specifying the target to inject the script into.
- `world` {{optional_inline}}
- : {{WebExtAPIRef("scripting.ExecutionWorld")}}. The execution environment for a script to execute in.

### Return value

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: scripting.ExecutionWorld
slug: Mozilla/Add-ons/WebExtensions/API/scripting/ExecutionWorld
tags:
- API
- Add-ons
- Extensions
- ExecutionWorld
- Reference
- Type
- WebExtensions
- scripting
browser-compat: webextensions.api.scripting.ExecutionWorld
---

{{AddonSidebar()}}

Specifies the execution environment of a script injected with {{WebExtAPIRef("scripting.executeScript()")}}
or registered with {{WebExtAPIRef("scripting.registerContentScripts()")}}.

## Type

Values of this type are strings. Possible values are:

- `ISOLATED`

The default execution environment of [content scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts).
This environment is isolated from the page's context: while they share the same document, the global scopes and available APIs differ.

- `MAIN`

The execution environment of the web page. This environment is shared with the web page, without isolation.
Scripts in this environment do not have any access to APIs that are only available to content scripts.

> **Warning:** Due to the lack of isolation, the web page can detect the executed code and interfere with it.
> Do not use the `MAIN` world unless it is acceptable for web pages to read, access, or modify the logic or data that flows through the executed code.
## Browser compatibility

{{Compat}}

{{WebExtExamples}}

> **Note:** This API is based on Chromium's [`chrome.scripting`](https://developer.chrome.com/docs/extensions/reference/scripting/#type-ExecutionWorld) API.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Alternatively, you can get permission temporarily in the active tab and only in

- {{WebExtAPIRef("scripting.ContentScriptFilter")}}
- : Specifies the IDs of scripts to retrieve with {{WebExtAPIRef("scripting.getRegisteredContentScripts()")}} or to unregister with {{WebExtAPIRef("scripting.unregisterContentScripts()")}}.
- {{WebExtAPIRef("scripting.ExecutionWorld")}}
- : Specifies the execution environment of a script injected with {{WebExtAPIRef("scripting.executeScript()")}} or registered with {{WebExtAPIRef("scripting.registerContentScripts()")}}.
- {{WebExtAPIRef("scripting.InjectionTarget")}}
- : Details of an injection target.
- {{WebExtAPIRef("scripting.RegisteredContentScript")}}
Expand Down

0 comments on commit 8939214

Please sign in to comment.