Note that there are some explanatory texts on larger screens.

plurals
  1. POFirefox extension not working
    text
    copied!<p>I've created a Firefox extension but I can't use it (nothing happens). Does someone know why ?</p> <p>The module hierarchy</p> <p>my_firefox_extension</p> <ul> <li>chrome.manifest</li> <li>install.rdf</li> <li>chrome/ <ul> <li>content/ <ul> <li>locale.html</li> <li>overlay.js</li> <li>sample.xul</li> </ul></li> </ul></li> </ul> <p>The code </p> <p>chrome.manifest</p> <pre><code>content firefox_extension chrome/content/ overlay chrome://browser/content/browser.xul chrome://firefox_extension/content/sample.xul </code></pre> <p>install.rdf</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"&gt; &lt;Description about="urn:mozilla:install-manifest"&gt; &lt;em:id&gt;displaypages@bruno.com&lt;/em:id&gt; &lt;em:name&gt;Display the page locale&lt;/em:name&gt; &lt;em:description&gt;Welcome to this extension that displays the page locale when a user opens a new tab or windows&lt;/em:description&gt; &lt;em:version&gt;0.1&lt;/em:version&gt; &lt;em:creator&gt;Bruno Da Silva&lt;/em:creator&gt; &lt;em:homepageURL&gt;https://www.example.com&lt;/em:homepageURL&gt; &lt;em:type&gt;2&lt;/em:type&gt; &lt;!-- Mozilla Firefox --&gt; &lt;em:targetApplication&gt; &lt;Description&gt; &lt;em:id&gt;{ec8030f7-c20a-464f-9b0e-13a3a9e97384}&lt;/em:id&gt; &lt;em:minVersion&gt;3.0&lt;/em:minVersion&gt; &lt;em:maxVersion&gt;4.0.*&lt;/em:maxVersion&gt; &lt;/Description&gt; &lt;/em:targetApplication&gt; &lt;/Description&gt; &lt;/RDF&gt; </code></pre> <p>sample.xul</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;overlay id="firefox_extension-browser-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"&gt; &lt;script type="application/x-javascript" src="chrome://firefox_extension/content/overlay.js"/&gt; &lt;/overlay&gt; </code></pre> <p>overlay.js</p> <pre><code>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); }); </code></pre> <p>locale.html</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" &gt; &lt;head&gt; &lt;title&gt;Page displayed when a user opens a new tab or window&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;Some text&lt;p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload