Closed Bug 2016369 Opened 8 months ago Closed 8 months ago

Import attribute CSS fails with moz-extension:

Categories

(WebExtensions :: General, defect, P3)

defect

Tracking

(firefox150 fixed)

RESOLVED FIXED
150 Branch
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

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.

Depends on: 1989109

Hmm, but comment 0 seems to claim that json works, right? So probably not quite?

Flags: needinfo?(dminor)
Blocks: js-lang
Severity: -- → S3
Priority: -- → P3

(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: nobody → dminor
No longer depends on: 1989109
Flags: needinfo?(dminor)

We're failing MimeTypeMatchesExpectedModuleType, the mime type for the css module is coming back from the extension as application/x-unknown-content-type.

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?

Flags: needinfo?(rob)

(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.

Flags: needinfo?(rob)

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.

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.

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.

Attachment #9546505 - Attachment description: Bug 2016369 - Set ContentType in SubstituteChannel; r=robwu! → Bug 2016369 - Set ContentType for CSS in SubstituteChannel; r=robwu!
Attachment #9546505 - Attachment description: Bug 2016369 - Set ContentType for CSS in SubstituteChannel; r=robwu! → Bug 2016369 - Set ContentType for CSS in ExtensionProtocolHandler; r=robwu!
Status: NEW → RESOLVED
Closed: 8 months ago
Resolution: --- → FIXED
Target Milestone: --- → 150 Branch

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.

Component: JavaScript Engine → General
Product: Core → WebExtensions

Release note available for review in Bug-2016369 import css attribute in extensions fix #43774

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: