Open hdodov opened 9 months ago
In addition, chrome-extension://__MSG_@@extension_id__
appears to resolve correctly in popup scripts as well. If I add it in the same CSS file that is loaded both in the popup and the content script — it works in both places.
Maybe one possible solution is to just always prepend chrome-extension://__MSG_@@extension_id__
, regardless of the script's location (popup or content)?
As @KTibow suggested in the Vite Discord server where I asked for help, the experimental renderBuiltUrl
option can be used:
vite.config.ts:
export default defineConfig({
plugins: [solidPlugin(), crx({ manifest })],
experimental: {
renderBuiltUrl(filename, { hostType }) {
if (hostType === "css") {
return `chrome-extension://__MSG_@@extension_id__/${filename}`;
}
},
},
});
It prepends the string to the output asset URLs and works perfectly. Still, in my opinion, it'd be great if CRXJS uses this internally, so end-users don't have to face this issue.
Build tool
Vite
Where do you see the problem?
Describe the bug
I have a simple content script that imports CSS with fonts:
manifest.json:
content.tsx:
index.css:
I do the same in the extension popup and it works perfectly there. However, in the content script, it results in the extension attempting to load the resources from the visited website, and you obviously get a 404:
This problem has been raised in Stack Overflow and the solution is to use a special string in the CSS resource path, as explained in the Chrome docs:
And indeed, if I build my extension, go to the generated CSS, and manually prepend
chrome-extension://__MSG_@@extension_id__
, everything starts working. In other words, this:…has to turn to this:
Reproduction
Create a content script and try to import any CSS asset.
Logs
No response
System Info