-
Notifications
You must be signed in to change notification settings - Fork 22.6k
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
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).
files/en-us/mozilla/add-ons/webextensions/api/runtime/onuserscriptconnect/index.md
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/api/runtime/onuserscriptmessage/index.md
Show resolved
Hide resolved
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
files/en-us/mozilla/add-ons/webextensions/api/userscripts/registereduserscript/index.md
Outdated
Show resolved
Hide resolved
This pull request has merge conflicts that must be resolved before it can be merged. |
Co-authored-by: Rob Wu <rob@robwu.nl>
Removed inappropriate onUserScriptConnect example
files/en-us/mozilla/add-ons/webextensions/api/runtime/onuserscriptconnect/index.md
Outdated
Show resolved
Hide resolved
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/resetworldconfiguration/index.md
Show resolved
Hide resolved
|
||
Resets the configuration of a `USER_SCRIPT` world set by {{WebExtAPIRef("userScripts.configureWorld")}} to the defaults specified in {{WebExtAPIRef("userScripts.WorldProperties")}}. When the default world is reset, all worlds without an explicit configuration are also reset. | ||
|
||
Any scripts injected into a reset world are moved to the default `USER_SCRIPT` world. |
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.
Any scripts injected into a reset world are moved to the default `USER_SCRIPT` world. |
This is factually incorrect. The closest reasonable interpretation of this is that the default world's configuration is used upon reset, which is already stated above.
|
||
```js-nolint | ||
const resettingWorldConfiguration = await browser.userScripts.resetWorldConfiguration( | ||
worldId // string |
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.
worldId // string | |
worldId // optional string |
|
||
{{AddonSidebar}} | ||
|
||
The configuration of a `USER_SCRIPT` execution environment. |
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.
Please list all methods that uses this type: configureWorld, getWorldConfigurations.
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
- `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.
- : 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 [default CSP for content scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_Security_Policy#csp_for_content_scripts), which prohibits dynamic code execution, such as` eval()`. |
Added link that explains the default CSP.
files/en-us/mozilla/add-ons/webextensions/manifest.json/optional_permissions/index.md
Outdated
Show resolved
Hide resolved
@@ -132,6 +132,7 @@ These permissions are available in Manifest V2 and above unless otherwise noted: | |||
- `theme` | |||
- `topSites` | |||
- `unlimitedStorage` | |||
- `userScripts` (This permission is [optional-only](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/optional_permissions#optional-only_permissions) in Firefox. In Chrome, the extension user must also activate [developer mode](https://developer.chrome.com/docs/extensions/reference/api/userScripts#developer_mode_for_extension_users).) |
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.
- `userScripts` (This permission is [optional-only](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/optional_permissions#optional-only_permissions) in Firefox. In Chrome, the extension user must also activate [developer mode](https://developer.chrome.com/docs/extensions/reference/api/userScripts#developer_mode_for_extension_users).) | |
- 'userScripts' (see [userScripts permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts#permissions)) |
Just link to the full documentation for brevity. Those who care are better served by the full documentation.
> No optional-only permissions were generally available at the time of writing, December 2024. | ||
The optional-only API permissions are: | ||
|
||
- 'userScripts' (Firefox only) |
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.
Don't forget to also list userScripts in the list of optional permissions above.
Optional-only is a subset of optional_permissions.
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
Co-authored-by: Rob Wu <rob@robwu.nl>
Co-authored-by: Rob Wu <rob@robwu.nl>
files/en-us/mozilla/add-ons/webextensions/api/userscripts/configureworld/index.md
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/api/userscripts/resetworldconfiguration/index.md
Show resolved
Hide resolved
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.
I am approving because the PR can be merged once my suggestions have all been applied. If in doubt, please ping me and I will offer an expedited review.
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/register/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/api/userscripts/registereduserscript/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/api/userscripts/resetworldconfiguration/index.md
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/api/userscripts/userscriptfilter/index.md
Outdated
Show resolved
Hide resolved
|
||
To use the API, call `{{WebExtAPIRef("userScripts.register","register()")}}` passing in an object defining the scripts to register. The method returns a Promise that is resolved with a `{{WebExtAPIRef("userScripts.RegisteredUserScript","RegisteredUserScript")}}` object. | ||
- In Firefox, `userScripts` is an [optional-only permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/optional_permissions#optional-only_permissions) declared in the `optional_permissions` manifest key. Your extension must check that the permission has been granted by checking the availability of the `userScripts` API namespace or using {{WebExtAPIRef("permissions.contains()")}} and, if not, request it using {{WebExtAPIRef("permissions.request()")}}. | ||
- in Chrome, `userScripts` is an install time requested permission declared in the [`permissions` manifest key](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions). However, to enable use of the API, users must [turn on the developer environment in Chrome](https://developer.chrome.com/docs/extensions/reference/api/userScripts#developer_mode_for_extension_users). |
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.
Note: Chrome is working on a per-extension toggle independently of the Developer Mode checkbox. That implementation is tracked at https://issues.chromium.org/issues/390138269
Co-authored-by: Rob Wu <rob@robwu.nl>
files/en-us/mozilla/add-ons/webextensions/api/userscripts/registereduserscript/index.md
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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