Import attribute CSS fails with moz-extension:
Categories
(WebExtensions :: General, defect, P3)
Tracking
(firefox150 fixed)
| Tracking | Status | |
|---|---|---|
| firefox150 | --- | fixed |
People
(Reporter: erosman, Assigned: dminor)
References
(Blocks 1 open bug)
Details
(Keywords: dev-doc-complete)
Attachments
(2 external files)
The follow code fails in extension context and DevTools.
It works fine on Chrome.
import('/content/nav.css', {with: {type: 'css'}})
.then(console.log)
.catch(console.error);
// TypeError: error loading dynamically imported module: moz-extension://f5.../content/nav.css
For reference, the following works fine on Firefox.
import('/manifest.json', {with: {type: 'json'}})
.then(console.log)
.catch(console.error);
Ubuntu 24.04
Nightly 149.0a1
| Reporter | ||
Comment 1•8 months ago
|
||
See also: bug 1736059, bug 1986681
| Assignee | ||
Comment 2•8 months ago
|
||
I think this is likely the same problem as Bug 1989109, we use a different loader for internal modules, and that one doesn't support import attributes yet.
Comment 3•8 months ago
|
||
Hmm, but comment 0 seems to claim that json works, right? So probably not quite?
Updated•8 months ago
|
| Assignee | ||
Comment 4•8 months ago
|
||
(In reply to Emilio Cobos Álvarez [:emilio] from comment #3)
Hmm, but comment 0 seems to claim that json works, right? So probably not quite?
You're right, I misread that, so it must be a different problem. TypeError might mean we're failing a content-type check somewhere that we're passing for json modules.
| Assignee | ||
Comment 5•8 months ago
|
||
We're failing MimeTypeMatchesExpectedModuleType, the mime type for the css module is coming back from the extension as application/x-unknown-content-type.
| Assignee | ||
Comment 6•8 months ago
|
||
This seems like it should be easy to fix, but I'm not familiar at all with our web extensions code. Rob, I was wondering if you could help me figure out where the content-type is being set for files in an extension?
Comment 7•8 months ago
|
||
(In reply to Dan Minor [:dminor] from comment #6)
This seems like it should be easy to fix, but I'm not familiar at all with our web extensions code. Rob, I was wondering if you could help me figure out where the content-type is being set for files in an extension?
I saw the application/x-unknown-content-type issue before, with debugging and analysis in https://bugzilla.mozilla.org/show_bug.cgi?id=1433890#c7 and later.
I have also written up about the flow of creating the relevant channels (and mention of css handler) in https://bugzilla.mozilla.org/show_bug.cgi?id=1826867#c7
(both are about document loads, not subresource loads; the extension channel resolution part is however identical from the ExtensionProtocolHandler's perspective though)
In the parent process, the channel is created here: https://searchfox.org/firefox-main/rev/5c6d4ae3f944972de57bd80adb49fcf18fa5f3bb/netwerk/protocol/res/ExtensionProtocolHandler.cpp#508-547
The content type is set here based on the URL: https://searchfox.org/firefox-main/rev/5c6d4ae3f944972de57bd80adb49fcf18fa5f3bb/netwerk/protocol/res/ExtensionProtocolHandler.cpp#884
I see other uses of NS_NewSimpleChannel that sometimes explicitly calling SetContentType, so perhaps we forgot one such call somewhere in ExtensionProtocolHandler.cpp.
| Assignee | ||
Comment 8•8 months ago
|
||
Thanks, that's very helpful, it looks like the problem is in ExtensionProtocolHandler::SubstituteChannel, we sometimes create a new channel for css files, but don't set the content type there.
| Assignee | ||
Comment 9•8 months ago
|
||
The current error message is bad, we should at least mention that it
was the CSS module compilation that failed.
I've also added some basic logging for when the module mime type check
fails, even though I'm familiar with the code, it took me more time
than it should have to realize this was what was causing the css module
in the extension to fail loading.
| Assignee | ||
Comment 10•8 months ago
|
||
We sometimes create a new channel for css files, but did not set the
content type, which caused loading of CSS module scripts to fail in
extension code.
Updated•8 months ago
|
Updated•8 months ago
|
Comment 11•8 months ago
|
||
Comment 12•8 months ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/44961127084f
https://hg.mozilla.org/mozilla-central/rev/9570c236af2e
Comment 13•7 months ago
|
||
Moving to WebExtensions product for better visibility of the fix. Ultimately the main fix was in the extension protocol handler.
I don't know if we should document this bugfix, but at least having it in product:WebExtensions should make it easier to find.
Updated•7 months ago
|
Comment 14•6 months ago
|
||
Release note available for review in Bug-2016369 import css attribute in extensions fix #43774
Description
•