-
Notifications
You must be signed in to change notification settings - Fork 22.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Bug 1943050 - new userScripts
API content
#38073
base: main
Are you sure you want to change the base?
Bug 1943050 - new userScripts
API content
#38073
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rebase your PR on the (presumably final) state of the legacy documentation move? Then I can more easily compare the difference with this link: https://github.com/rebloor/content/compare/Bug-1943050-userScripts-API-move-legacy-content..Bug-1943050-userScripts-API-new-content
|
||
{{Compat}} | ||
|
||
> [!NOTE] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's delete all of this copyright etc stuff (in every article related to userScripts).
The userScripts API is designed together with me in the WECG; we don't need to call out Chromium's source and license header here.
- `port` | ||
- : {{WebExtAPIRef('runtime.Port')}}. An object connecting the current script to the other context. | ||
|
||
## Examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's delete this full example. It is inaccurate and incomplete, and I'd like to get the primary doc completed without being blocked on the example.
- Missing
userScripts.configureWorld()
call. - Uses
browserAction
(which is MV2-only) instead ofaction
API (which is MV3 only). - Example shows bad practice of storing the port in a global variable with the expectation of the variable sticking around; this is not guaranteed in event pages/service workers (because these may suspend).
Fired when a connection is made with a user script from one of the extension's [`USER_SCRIPT` worlds](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/ExecutionWorld). | ||
|
||
A user script can only connect and then sent messages from a `USER_SCRIPT` world that is configured by {{WebExtAPIRef('userScripts.configureWorld()')}} with `messaging` set to `true`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a note that this event requires the "userScripts" permission (in Firefox). In Chrome, the onUserScriptConnect
and onUserScriptMessage
events are always present, even in extensions that don't declare the userScripts permission, even if there is no way for that event to fire.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Use this event to listen for messages sent from one of the extension's [`USER_SCRIPT` worlds](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/ExecutionWorld). | ||
|
||
A user script can only send messages using {{WebExtAPIRef('runtime.sendMessage')}} from a `USER_SCRIPT` world that is configured by {{WebExtAPIRef('userScripts.configureWorld()')}} with `messaging` set to `true`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(already mentioned before; adding for completeness)
Let's add a note that this event requires the "userScripts" permission (in Firefox). In Chrome, the onUserScriptConnect
and onUserScriptMessage
events are always present, even in extensions that don't declare the userScripts permission, even if there is no way for that event to fire.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
files/en-us/mozilla/add-ons/webextensions/api/runtime/onuserscriptmessage/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md
Outdated
Show resolved
Hide resolved
|
||
- `allFrames` {{optional_inline}} | ||
- : `boolean`. If `allFrames` is `true`, the script is injected into all of a page's frames. By default, it's `false` and the script is only injected into the top frame. | ||
- `id` {{optional_inline}} for {{WebExtAPIRef("userScripts.update()")}} calls, required for {{WebExtAPIRef("userScripts.register()")}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ID is always required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
- `world` {{optional_inline}} | ||
- : {{WebExtAPIRef("userScripts.ExecutionWorld")}}. The execution environment to use to run the scripts. Defaults to "USER_SCRIPT". | ||
- `worldId` {{optional_inline}} | ||
- : `string`. ID of a user script world execute the script in. Only valid if `world` is `USER_SCRIPT` or omitted. If `worldId` is omitted, the script is execute in the default `USER_SCRIPT` world (""). Values with leading underscores (`_`) are reserved. The maximum length is 256 characters. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refer to configureWorld
for ease of discovery of what world configurations are.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Rob--W don't follow this feedback. Isn't the main reference for worlds on the API's root page. Or did you mean a reference to 'getWorldConfigurations'?
This pull request has merge conflicts that must be resolved before it can be merged. |
Co-authored-by: Rob Wu <rob@robwu.nl>
- `worldId` {{optional_inline}} | ||
- : `string`. The identifier for the world. Values with leading underscores (`_`) are reserved. The maximum length is 256. Defaults to the default `USER_SCRIPT` world (""). | ||
- `csp` {{optional_inline}} | ||
- : string`. The world's Content Security Policy (CSP). Defaults to the standard content scripts CSP, which prohibits dynamic code execution, such as `eval()`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶
- : string`. The world's Content Security Policy (CSP). Defaults to the standard content scripts CSP, which prohibits dynamic code execution, such as `eval()`. | |
- : string`. The world's Content Security Policy (CSP). Defaults to the standard content scripts CSP, which prohibits dynamic code execution, such as`eval()`. |
Removed inappropriate onUserScriptConnect example
Description
Addresses the documentation needs of Bug 1943050 Enable userScripts API by default by adding the documentation for the user script, API and related APIs.
add explicit cross-references to the new example extension (Add example using MV3 userScripts API webextensions-examples#576)Related issues and pull requests
Moving old API to legacy: #37975 (comment)
Addition of related browser compatibility data:
webExtension.api.userScripts
browser-compat-data#25913Extension workshop updates: Bug-1943050 userScripts API permissions content mozilla/extension-workshop#2013