Dynamic import fails in content script in MV3 extension
Categories
(WebExtensions :: General, defect, P2)
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 |
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.
Reporter | ||
Updated•2 years ago
|
Comment 1•2 years ago
|
||
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.
Updated•2 years ago
|
Updated•2 years ago
|
Comment 2•2 years ago
|
||
The severity field is not set for this bug.
:rpl, could you have a look please?
For more information, please visit auto_nag documentation.
Comment 3•2 years ago
|
||
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?
Comment 4•2 years ago
|
||
For modules we use CORS loads and those seem to require a web_accessible_resource since bug 1783078.
Comment 5•2 years ago
|
||
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
.
Comment 6•2 years ago
|
||
(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?
Comment 7•2 years ago
|
||
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.
Updated•2 years ago
|
Updated•2 years ago
|
Updated•2 years ago
|
Description
•