Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for ExecutionWorld of scripting.executeScript API #24316

Merged
merged 4 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 within.
Rob--W marked this conversation as resolved.
Show resolved Hide resolved

### 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()")}},
Rob--W marked this conversation as resolved.
Show resolved Hide resolved
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.
Rob--W marked this conversation as resolved.
Show resolved Hide resolved

## 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