Open Bug 1803950 Opened 2 years ago Updated 2 years ago

Dynamic import fails in content script in MV3 extension

Categories

(WebExtensions :: General, defect, P2)

Firefox 109
defect

Tracking

(Not tracked)

People

(Reporter: kazz, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: [addons-jira])

Attachments

(1 file)

(deleted), application/x-zip-compressed
Details
Attached file webExtTest.zip (deleted) —

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/109.0

Steps to reproduce:

STR:

  • Save the attached extension
  • Open browser console (Ctrl+Shift+J) and enable multiprocess
  • Open about:debugging and load the extension
  • Open new tab and navigate to https://example.com.
  • Check the browser console

Actual results:

Actual:

  • Warned Module source URI is not allowed in this document: “moz-extension://49a14e05-5cc0-4c0c-95e5-501c868ac87b/mjs/content-loader.js”.
  • And also thrown TypeError: error loading dynamically imported module

Expected results:

Expected:

  • Hello Example Domain to be logged.

If you change the "manifest_version" to 2 in manifest.json, it works as expected.

Product: Firefox → WebExtensions

Currenty, a dynamic import is only possible when a script is declared in web_accessible_resources (bug 1783078).

IMO we should consider dropping the web_accessible_resources-requirement for dynamic imports, since the resulting load is exclusively used in a content script. scripting.executeScript is not subjected to the web_accessible_resources requirement either.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Component: Untriaged → General

The severity field is not set for this bug.
:rpl, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(lgreco)

Support for dynamic imports in content scripts was introduced in bug 1536094, and refactored in bug 1761938.

Tom, do you know why this load is rejected (beyond comment 1), and how feasible it is to resolve this bug?

For modules we use CORS loads and those seem to require a web_accessible_resource since bug 1783078.

Flags: needinfo?(evilpies)

There might also be another issue. It looks to me like for dynamic imports from WebExtensions we don't get the WebExtension ModuleLoader in ModuleLoaderBase::GetCurrentModuleLoader.

Flags: needinfo?(jcoppeard)

(In reply to Tom S [:evilpie] from comment #5)
I don't know that much about web extensions, but yes it seems like that's what will happen. If content script runs in the context of the page's global then it will get the page's module loader, not the WebExtension module loader.

I'm not sure what's expected here and can't find a spec for executeScript. Tom is this defined somewhere?

Flags: needinfo?(jcoppeard)

The module loading of content script should ideally be independent of the web page. If at all possible, associate it with the Sandbox constructed at https://searchfox.org/mozilla-central/rev/4ebfb48f7e82251145afa4a822f970931dd06c68/toolkit/components/extensions/ExtensionContent.jsm#838-874.

Tom, are you interested in working on this bug?

Flags: needinfo?(evilpies)

I am not able to work on this in the short term.

Flags: needinfo?(evilpies)
Severity: -- → S4
Priority: -- → P2
Whiteboard: [addons-jira]
Blocks: manifest-v3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: