Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can a Firefox extension inject a local css file into a webpage?

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?

like image 359
Evgeny Shadchnev Avatar asked Apr 28 '10 17:04

Evgeny Shadchnev


People also ask

How do I add local extensions to Firefox?

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.

How do I add code to 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.


1 Answers

Use resource: instead of chrome:?

like image 66
matyr Avatar answered Sep 19 '22 08:09

matyr