How can a Firefox extension get its own version number programmatically?

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="" 
  <Description about="urn:mozilla:install-manifest">



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[";1"]
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.


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
    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[";1"]
    var addon = em.getItemForID("[email protected]");
    alert("My extension's version is " + addon.version);

With Add-on SDK its simple as:

var version = require("sdk/self").version;


In Web Extensions use the following:



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.