Categories

Retrieving Your Extension Version

From time to time when reviewing add-ons on AMO, I notice that the version number of the extension is hard-coded. The author needs it to fork some code because of API differences across versions of the Mozilla application, or perhaps some other reason.

Hard-coding is not necessary. In most cases the version should only be in install.rdf. The version can be retrieved from the nsIExtensionManager/nsIUpdateItem interfaces. Here’s the basic snippet:


var emid = "cooladdon@mydomain.com"; // Should correspond to em:id in install.rdf
var version = MyExt.getExtensionVersion(emid);
MyExt.getExtensionVersion = function(emid)
{
  var em = Components.classes["@mozilla.org/extensions/manager;1"]
    .getService(Components.interfaces.nsIExtensionManager);
  var addon = em.getItemForID(emid);
  var versionString = addon.version;
  return versionString;
}

And so it goes. You can retrieve other information about the extension via these interfaces.

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to StumbleUpon

7 comments to Retrieving Your Extension Version

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>