Firefox extension not working

I created the Firefox extension, but I can’t use it (nothing happens). Does anyone know why?

Module hierarchy

my_firefox_extension

  • chrome.manifest
  • install.rdf
  • chrome /
    • Contents /
      • locale.html
      • overlay.js
      • sample.xul

Code

chrome.manifest

content firefox_extension chrome/content/ overlay chrome://browser/content/browser.xul chrome://firefox_extension/content/sample.xul 

install.rdf

 <?xml version="1.0"?> <RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"> <Description about="urn:mozilla:install-manifest"> <em:id> displaypages@bruno.com </em:id> <em:name>Display the page locale</em:name> <em:description>Welcome to this extension that displays the page locale when a user opens a new tab or windows</em:description> <em:version>0.1</em:version> <em:creator>Bruno Da Silva</em:creator> <em:homepageURL>https://www.example.com</em:homepageURL> <em:type>2</em:type> <!-- Mozilla Firefox --> <em:targetApplication> <Description> <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id> <em:minVersion>3.0</em:minVersion> <em:maxVersion>4.0.*</em:maxVersion> </Description> </em:targetApplication> </Description> </RDF> 

sample.xul

 <?xml version="1.0"?> <overlay id="firefox_extension-browser-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script type="application/x-javascript" src="chrome://firefox_extension/content/overlay.js"/> </overlay> 

overlay.js

 function Read(file) { var ioService=Components.classes["@mozilla.org/network/io-service;1"] .getService(Components.interfaces.nsIIOService); var scriptableStream=Components .classes["@mozilla.org/scriptableinputstream;1"] .getService(Components.interfaces.nsIScriptableInputStream); var channel=ioService.newChannel(file,null,null); var input=channel.open(); scriptableStream.init(input); var str=scriptableStream.read(input.available()); scriptableStream.close(); input.close(); return str; } gBrowser.addEventListener("DOMContentLoaded", function(e) { var documentElement = e.originalTarget.defaultView.document; var div = documentElement.createElement("div"); div.innerHTML = Read("chrome://firefox_extension/content/locale.html"); documentElement.body.appendChild(div); }); 

locale.html

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" > <head> <title>Page displayed when a user opens a new tab or window</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <p>Some text<p> </body> </html> 
+4
source share
4 answers

You missed one parameter that probably causes errors:

 gBrowser.addEventListener("DOMContentLoaded", function(e) { var documentElement = e.originalTarget.defaultView.document; var div = documentElement.createElement("div"); div.innerHTML = Read("chrome://firefox_extension/content/locale.html"); documentElement.body.appendChild(div); }, false // missing parameter on addEventListener // add this and it might work ); 
+6
source

(Just guess, not tested)

NS_ERROR_FILE_TARGET_DOES_NOT_EXIST may be caused by an invalid script file reference in sample.xul

 <script type="application/x-javascript" src="chrome//firefox_extension/content/overlay.js"/> 
Attribute

src is missing a colon after chrome. It should be

 src="chrome://firefox_extension/content/overlay.js" 
0
source

Files in Firefox can be fixed.

Try to execute

Exit Firefox completely, then open the Firefox profile folder and delete or rename these files:

extensions.ini extensions.cache extensions.rdf

Starting with Firefox 4, delete or rename:

extensions.sqlite extensions.sqlite-journal (if found)

Note. Although the above files can be deleted, renaming them (for example, "extensionsOLD.ini", "extensionsOLD.cache", etc.) is generally considered more secure. This leads to the same result, but allows the user to receive any possible information from them.

Then try restarting the browser and installing them

Else is another method that might work (but don't know why and how they work)

Enable third-party cookies - go to Tools β†’ Options β†’ Privacy and select the Accept third-party cookies check box.

0
source

Does the extension work when used in a live development context , unlike problems with the xpi installer?

With Firefox closed, create an β€œindex” file with the same name as your extensions Description: ID (as found in your install.rdf) in the folder / extensions / profile and edit it so that it contains the path to your extension folder ( root containing containing install.rdf and chrome.manifest).

eg. The identifier is helloworlds helloworld@mozilla.doslash.org and we would like to register it in X: \ Dev \ helloworld \ (i.e. there is a File X: \ Dev \ helloworld \ install.rdf, etc.). Just put one line in the file this way: profile folder / extensions / helloworld@mozilla.doslash.org

X: \ Dev \ helloworld \ - mark trailing slash and no CR; it should be a SINGLE LINE

(Re) Launch Firefox and make sure your extension is installed.

This will help you ensure that the extension works before you begin to solve installation problems.

0
source

All Articles