Skip to content

Bug-2011234: remove the ability to dynamically execute code in moz-extension: documents#43108

Merged
rebloor merged 14 commits intomdn:mainfrom
rebloor:Bug-2011234-remove-ability-to-dynamically-execute-code-in-their-moz-extension-documents-with-tabs-and-scripting.executeScript
Mar 1, 2026
Merged

Bug-2011234: remove the ability to dynamically execute code in moz-extension: documents#43108
rebloor merged 14 commits intomdn:mainfrom
rebloor:Bug-2011234-remove-ability-to-dynamically-execute-code-in-their-moz-extension-documents-with-tabs-and-scripting.executeScript

Conversation

@rebloor
Copy link
Copy Markdown
Contributor

@rebloor rebloor commented Feb 12, 2026

Description

Addresses the dev-docs-needed requirements of Bug 2011234 Extensions can dynamically execute code in their moz-extension: documents with tabs/scripting.executeScript by:

  • the addition of a release note
  • removal of references to extensions automatically getting host permissions for their origin from the documentation for the permissions and host_permissions manifest keys.
  • removal information about executing scripts in an extension's origin from tab.executeScript.

Although this change also applies to tabs.insertCSS, tabs.removeCSS, scripting.executeScript, scripting.insertCSS, and scripting.removeCSS, no explicit reference to the feature was made in those methods. No documentation changes were made, as the default expectation is that a web page can fetch() in its own URLs, which also applies to extension documents.

@rebloor rebloor self-assigned this Feb 12, 2026
@rebloor rebloor requested review from a team as code owners February 12, 2026 18:05
@rebloor rebloor requested review from Rob--W and removed request for a team February 12, 2026 18:06
@rebloor rebloor added the Content:WebExt WebExtensions docs label Feb 12, 2026
@rebloor rebloor requested review from dipikabh and removed request for a team February 12, 2026 18:06
@github-actions github-actions Bot added Content:Firefox Content in the Mozilla/Firefox subtree size/m [PR only] 51-500 LoC changed labels Feb 12, 2026
Comment thread files/en-us/mozilla/add-ons/webextensions/api/tabs/executescript/index.md Outdated
Comment thread files/en-us/mozilla/add-ons/webextensions/manifest.json/permissions/index.md Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 12, 2026

Preview URLs (7 pages)
External URLs (8)

URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/executeScript
Title: tabs.executeScript()


URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/host_permissions
Title: host_permissions


URL: /en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions
Title: permissions

(comment last updated: 2026-02-27 18:21:56)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Comment thread files/en-us/mozilla/add-ons/webextensions/manifest.json/host_permissions/index.md Outdated
Comment thread files/en-us/mozilla/add-ons/webextensions/manifest.json/permissions/index.md Outdated
Comment thread files/en-us/mozilla/firefox/releases/149/index.md Outdated
Comment thread files/en-us/mozilla/add-ons/webextensions/api/tabs/executescript/index.md Outdated
You must have the permission for the page's URL either explicitly, as a [host permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#host_permissions), or using the [activeTab permission](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#activetab_permission). Note that some special pages do not allow this permission, including reader view, view-source, and PDF viewer pages.

You can also inject code into pages packaged with your own extension:
You _cannot_ inject code into:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the enumeration and just state that content scripts cannot be run in extension documents. If an extension wants to dynamically run code, they could register a runtime.onMessage listener and send a message there instead. Please linkify the runtime.onMessage API, which itself also provides pointers to relevant APIs: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage

rebloor and others added 5 commits February 14, 2026 04:20
Co-authored-by: Rob Wu <rob@robwu.nl>
Co-authored-by: Rob Wu <rob@robwu.nl>
Co-authored-by: Rob Wu <rob@robwu.nl>
Co-authored-by: Rob Wu <rob@robwu.nl>
@rebloor rebloor requested a review from Rob--W February 13, 2026 17:56
Copy link
Copy Markdown
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please read the review feedback and merge after applying it. If in doubt, please ping me for another review.

We now also link to runtime.onMessage, but "the example use cases" do not include the specific case here. Please add a bullet point listing this use case:
"in an extension document in a tab to listen for messages from the background script or anywhere else"

This use case is already pointed to in tabs.sendMessage as "extension pages/iframes that belong to the extension and are running in the specified tab."

Comment thread files/en-us/mozilla/add-ons/webextensions/api/tabs/executescript/index.md Outdated
Comment on lines 18 to 19
You _cannot_ inject code into any of the browser's built-in pages, such as `about:debugging`, or `about:addons`, or the page that opens when you open a new empty tab.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You _cannot_ inject code into any of the browser's built-in pages, such as `about:debugging`, or `about:addons`, or the page that opens when you open a new empty tab.

The last part of the previous paragraph already explains that certain pages cannot be scripted, so I am suggesting to drop this (repetitive) part.

Comment thread files/en-us/mozilla/add-ons/webextensions/content_scripts/index.md Outdated

<!-- ### Removals -->

The ability of extensions to dynamically execute code in their `moz-extension:` documents with {{WebExtAPIRef("tabs.executeScript")}}, {{WebExtAPIRef("tabs.insertCSS")}}, {{WebExtAPIRef("tabs.removeCSS")}}, {{WebExtAPIRef("scripting.executeScript")}}, {{WebExtAPIRef("scripting.insertCSS")}}, and {{WebExtAPIRef("scripting.removeCSS")}} is deprecated. The feature is no longer available in Firefox Nightly, and the beta and release versions of Firefox provide a warning in the tab's console. This restriction will apply to all versions of Firefox 152 and later. ({{bug(2011234)}})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we should explicitly recommend or link to alternatives from here, in case it is not obvious. E.g. referring to runtime.onMessage as an alternative for most cases.

rebloor and others added 2 commits February 25, 2026 05:29
@rebloor
Copy link
Copy Markdown
Contributor Author

rebloor commented Feb 24, 2026

@Rob--W unfortunately, I can't figure out what your intention was with the comment about "Please add a bullet point listing this use case". Can you clarify? The other changes have been made. Note, I've modified the wording in the "Extensions cannot run content scripts in extension documents." paragraph, as I wasn't sure it was entirely clear. I've also added this paragraph to scripting/executeScript (was this what your comment about the bullet point referred to?)

@rebloor rebloor requested a review from Rob--W February 24, 2026 22:51
Copy link
Copy Markdown
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rob--W unfortunately, I can't figure out what your intention was with the comment about "Please add a bullet point listing this use case". Can you clarify?

The onMessage documentation (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/onMessage) has a bullet list of use cases. I am requesting to explicitly list the use case that we are now prominently mentioning (as an alternative to the deprecated executeScript usage).

I've also added this paragraph to scripting/executeScript (was this what your comment about the bullet point referred to?)

That is not what I was referring to, but as tabs.executeScript and scripting.executeScript have the same capabilities, it makes sense to include the same information there, so I am okay with keeping the same text there.

Using methods (1) and (2), you can only load scripts into pages whose URLs can be represented using a [match pattern](/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns).

Using method (3), you can also load scripts into pages packaged with your extension, but you can't load scripts into privileged browser pages (like `about:debugging` or `about:addons`).
Using method (3), you cannot load scripts into pages packaged with your extension, privileged browser UI pages (such as `about:debugging`, `about:addons`, reader view, view-source, or the PDF viewer).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This text now contains the correction I suggested before, but the other part of my feedback below the suggested text has not been applied. Could you read my previous review at #43108 (comment) and apply the full suggestion?

@rebloor
Copy link
Copy Markdown
Contributor Author

rebloor commented Feb 26, 2026

@Rob--W sorry for the slow uptake on your feedback. Hopefully, everything is done now.

@rebloor rebloor requested a review from Rob--W February 26, 2026 22:39
Copy link
Copy Markdown
Member

@Rob--W Rob--W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with the changes applied. Please check for typos before merging.

Comment thread files/en-us/mozilla/add-ons/webextensions/content_scripts/index.md Outdated
Comment on lines 81 to 84

### Limitations

Whole tabs or frames may be loaded using [`data:` URI](/en-US/docs/Web/URI/Reference/Schemes/data), {{DOMxRef("URL.createObjectURL_static", "Blob")}} objects, and other similar techniques. Support of content scripts injection into such special documents varies across browsers, see the Firefox [bug #1411641 comment 41](https://bugzil.la/1411641#c41) for some details.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted the whole section because it is obsolete. I merged the content with the new section.

Suggested change
### Limitations
Whole tabs or frames may be loaded using [`data:` URI](/en-US/docs/Web/URI/Reference/Schemes/data), {{DOMxRef("URL.createObjectURL_static", "Blob")}} objects, and other similar techniques. Support of content scripts injection into such special documents varies across browsers, see the Firefox [bug #1411641 comment 41](https://bugzil.la/1411641#c41) for some details.

Comment thread files/en-us/mozilla/add-ons/webextensions/content_scripts/index.md Outdated
Co-authored-by: Rob Wu <rob@robwu.nl>

If an extension wants to run code in an extension page dynamically, it can include a script in the page. This script contains the code to run and registers a {{WebExtAPIRef("runtime.onMessage")}} listener that implements a way to execute the code. The extension can then send a message to the listener to trigger the code's execution.

### Limitations
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[markdownlint] reported by reviewdog 🐶
error MD024/no-duplicate-heading Multiple headings with the same content [Context: "Limitations"]

@rebloor rebloor merged commit 2869180 into mdn:main Mar 1, 2026
8 checks passed
@rebloor rebloor deleted the Bug-2011234-remove-ability-to-dynamically-execute-code-in-their-moz-extension-documents-with-tabs-and-scripting.executeScript branch March 1, 2026 15:52
jdatapple pushed a commit to jdatapple/content that referenced this pull request Mar 6, 2026
…xtension:` documents (mdn#43108)

* Bug-2011234: remove the ability to dynamically execute code in `moz-extension:` documents

* Apply suggestions from linter

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Apply suggestions from review

Co-authored-by: Rob Wu <rob@robwu.nl>

* Apply suggestions from review

Co-authored-by: Rob Wu <rob@robwu.nl>

* Apply suggestion from @Rob--W

Co-authored-by: Rob Wu <rob@robwu.nl>

* Apply suggestion from @Rob--W

Co-authored-by: Rob Wu <rob@robwu.nl>

* Further clarifications of dynamic code execution in extension documents

* Apply suggestions from review

Co-authored-by: Rob Wu <rob@robwu.nl>

* Further feedback related changes

* typo

* Further feedback changes

* Apply suggestions from @Rob--W review

Co-authored-by: Rob Wu <rob@robwu.nl>

* Minor corrections

* Reapply deletion

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Rob Wu <rob@robwu.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:Firefox Content in the Mozilla/Firefox subtree Content:WebExt WebExtensions docs size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants