While developing the Accentuate.us Firefox add-on we ran into a bit of a snag. Our API requires that the user-agent begin with
Accentuate.us/version for analytics, random-hit spam prevention, and the ability to handle any future version conflicts. This requires gathering the add-on’s version number, which is specified in
The solution was rather simple but a little difficult to track down at first, so I’ve included it here for convenience:
The difference is minor but important. The code in
try is for Gecko \< 2, which grabs the extension manager from
Components.classes. In Gecko > 2, the add-on manager is imported. Once you have the add-on manager object, obtaining the version is trivial.
Relatedly, we had to have the line for initializing the Charlifter (legacy name for Accentuate.us)
Lifter object in both places because the version number is needed immediately upon initialization for a language list call, which the callback style of Gecko 2’s add-on manager interferes with.