I've created a Firefox extension but I can't use it (nothing happens). Does someone know why ?
The module hierarchy
my_firefox_extension
- chrome.manifest
- install.rdf
- chrome/
- content/
- locale.html
- overlay.js
- sample.xul
- content/
The 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=""
xmlns:em="">
<Description about="urn:mozilla:install-manifest">
<em:id>[email protected]</em:id>
<em:name>Display the page locale</em:name>
<em:description>Wele 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>;/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=".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/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var scriptableStream=Components
.classes["@mozilla/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" ".dtd">
<html xmlns="" 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>
I've created a Firefox extension but I can't use it (nothing happens). Does someone know why ?
The module hierarchy
my_firefox_extension
- chrome.manifest
- install.rdf
- chrome/
- content/
- locale.html
- overlay.js
- sample.xul
- content/
The 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/1999/02/22-rdf-syntax-ns#"
xmlns:em="http://www.mozilla/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>[email protected]</em:id>
<em:name>Display the page locale</em:name>
<em:description>Wele 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.</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/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/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var scriptableStream=Components
.classes["@mozilla/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/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3/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>
Share
Improve this question
edited May 27, 2011 at 13:50
munity wiki
13 revs, 2 users 96%
Bruno 7
- 1 At what point do you get the error? If it's during installation, set the preference extensions.logging.enabled in about:config, then try again, and copy in the errors seen in the Error Console. – Matthew Wilson Commented May 4, 2011 at 10:24
- @Matthew Wilson During the installation. I've updated my post to put the messages I get in the Console. – Bruno Commented May 4, 2011 at 10:36
-
What happens if you type
chrome://firefox_extension/content/overlay.js
on the address bar? – BrunoLM Commented May 4, 2011 at 11:55 -
Maybe it is the invalid target version
<em:maxVersion>6.0a1</em:maxVersion>
. Try<em:maxVersion>4.0.*</em:maxVersion>
instead. – BrunoLM Commented May 4, 2011 at 11:59 - 1 Could you post the XPI file somewhere? – speedball2001 Commented May 4, 2011 at 12:17
4 Answers
Reset to default 6You missed one parameter which is probably causing the 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
);
(Just guessing, no testing involved)
NS_ERROR_FILE_TARGET_DOES_NOT_EXIST
might be caused by incorrect script file reference in sample.xul
<script type="application/x-javascript" src="chrome//firefox_extension/content/overlay.js"/>
src
attribute is missing a colon after "chrome". It should be
src="chrome://firefox_extension/content/overlay.js"
The files in firefox could be corrected .
Try the following
Exit Firefox pletely, then open your Firefox profile folder and delete or rename these files:
extensions.ini extensions.cache extensions.rdf
Starting in Firefox 4, also delete or rename:
extensions.sqlite extensions.sqlite-journal (if found)
Note: Although the above files can be deleted, renaming them (e.g., "extensionsOLD.ini", "extensionsOLD.cache", etc.) is generally considered a safer option. This achieves the same result, but allows the user to retrieve any possibly required information from them later on.
Then try to restart the browser and install them
Else there is another method which may work (but dont know why/how they work)
Enable third party cookies - go to Tools -> Options -> Privacy and check the Accept third-party cookies box.
Does you extension work when using it in a live development environment, as opposed to having issues with the xpi installer?
With Firefox closed, create a “pointer” file with the same name as your extension’s Description:ID (as found in your install.rdf) in profile folder/extensions/ and edit it so that it contains the path to your extension’s folder (the root containing containing install.rdf and chrome.manifest files).
E.g. helloworld’s ID is [email protected] and we would like to register it in X:\Dev\helloworld\ (i.e. there is X:\Dev\helloworld\install.rdf file etc.). Just put a single line into the file at this path: profile folder/extensions/[email protected]
X:\Dev\helloworld\ - note trailing slash and no CR; this must be a SINGLE LINE
(Re)Start Firefox, and check that your extension is installed.
This will help you make sure that the extension works, before you start tackling installation issues.