Open Doliman100 opened 1 year ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.
Why are you importing the style this way? Extensions and Parcel both support loading styles directly:
{
"content_scripts": [{
"js": ["content.js"],
+ "css": ["content.css"],
"matches": ["<all_urls>"]
}],
"manifest_version": 3,
"name": "Test Extension",
"version": "1.0"
}
I'm working on an extension whose main part should only load on pages with "image/*" document.contentType
. There is a small loader script that loads into every page the user visits and checks for the document.contentType
. It loads the remaining content only for pages that meet the condition.
That's why I can't just include this style in manifest.json. I don't need it to load on every page the user visits.
The only images with document
are presumably SVG, right? Would a *.SVG
glob be enough?
There's a chance that you can also do the same via chrome.scripting.injectCSS()
from the background page, which is the official way to inject style.
Images may not have an extension, so URL analyzing is not a solution. My extension works for .jpg, .png, .webm or any other image type supported by Chrome's default image viewer.
chrome.scripting.injectCSS()
injects styles and scripts asynchronously, which causes background flickering.
document.adoptedStyleSheets
injects styles synchronously, which means the page will not open until all styles have been applied.
Here is the extension I am talking about:
https://chromewebstore.google.com/detail/simple-image-viewer/ohkbjcfpicefkagfejabhddfbmkeiojm
https://github.com/Doliman100/Simple-Image-Viewer
That's cool. The only thing I'd do differently is probably just load the CSS on every website and limit it to a specific class that your content.js adds. It's a super small stylesheet. But I understand if you want to be super efficient
🐛 bug report
When css is imported as text, the
content_scripts.css
orweb_accessible_resources
manifest fields shouldn't contain it. Because it doesn't exist as a file and already included in content.js. Currently, theweb_accessible_resources
field contains a reference to non-existing file. Thecontent_scripts.css
field is empty, but still included in resulting manifest.json. It should not be included if it is empty.🎛 Configuration (.babelrc, package.json, cli command)
cli command
🤔 Expected Behavior
./dist/manifest.json
:😯 Current Behavior
./dist/manifest.json
:💻 Code Sample
./src/content.js
:./src/manifest.json
:Distributable folder
./dist/
content: manifest.json, content.ec7ad09b.js (there is no content.9bf41e48.css).🌍 Your Environment