How do I programatically get my own Firefox extension's version number with Javascript?
My extension has an install.rdf file containing the version number similar to below. I want to extract the contents of the <em:version>
tag.
<?xml version="1.0" encoding="UTF-8"?>
<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:version>1.0</em:version>
...
</Description>
</RDF>
Add-ons allow developers to extend and modify the functionality of Firefox. They are written using standard Web technologies - JavaScript, HTML, and CSS - plus some dedicated JavaScript APIs.
Open about:memory . Click "measure" in Show memory reports. In the Main Process section, scroll down to Other Measurements. There you will find the installed (active) extensions with their names and their ids displayed as baseURL=moz-extension://[random-ids].
Most add-on data is stored in a folder in the Firefox user profile. However, some information is stored in the profile folder also. It's possible that there is a problem with the file(s) that store the extensions registry. Type about:support in the address bar and press enter.
In Firefox 4 (Gecko 2) the API has changed, so if you need to port to Firefox 4, this is the code (from here):
try {
// Firefox 4 and later; Mozilla 2 and later
Components.utils.import("resource://gre/modules/AddonManager.jsm");
AddonManager.getAddonByID("[email protected]", function(addon) {
alert("My extension's version is " + addon.version);
});
}
catch (ex) {
// Firefox 3.6 and before; Mozilla 1.9.2 and before
var em = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var addon = em.getItemForID("[email protected]");
alert("My extension's version is " + addon.version);
}
I've not got the full answer, but I found the Extended extension and had a look at the source code as it seemed like a good starting point, and from Googling some of the methods in that I found this snippet on MDC. The key bit of code would seem to be this:
var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"]
.getService(Components.interfaces.nsIExtensionManager);
var current = gExtensionManager.getItemForID("[email protected]").version;
You would have to replace [email protected]
with the appropriate ID for your extension.
Firefox 4 requires different code, see the other answer.
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