I'm writing a Firefox extension that needs to inject a css file into webpages. The css file is bundled with the extension, so I can access it using a chrome url
chrome://extensionid/content/skin/style.css
I'm trying to inject css like this when the page is loaded:
var fileref = document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", "chrome://extensionid/content/skin/style.css");
document.getElementsByTagName("head")[0].appendChild(fileref);
However, the css isn't loaded and Firebug shows 'Filtered chrome url' message instead of the file content, when I inspect the link
element I created. If I try to load this css file from an external server, everything's fine.
Is there are way to load a css file bundled with the extension?
In Firefox: Open the about:debugging page, click the This Firefox option, click the Load Temporary Add-on button, then select any file in your extension's directory. The extension now installs, and remains installed until you restart Firefox.
Loading the Add-on in FirefoxClick on Load Temporary Add-on button and choose the manifest. json file you just created. If everything was done correctly, you'll see the newly created add-on with some information about it and the icon we specified in the manifest.
Use resource:
instead of chrome:
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With