Were down to one reporter bug that needs to be fixed ASAP. Were not always getting the correct Product. By product I mean productName/productVersion. For example “Firefox/1.0+” or “SeaMonkey/1.8b2”. The below code is what’s currently being used. general.useragent.extra.firefox
is not exactly reliable, even less so than I originally thought. Leaving me with not many options. So my challenge is this: build an unbreakable function (or as close to it as possible) that will return the correct product/version for us to use. Should work with SeaMonkey > 1.7 and Firefox 1.0 and later. nsIXULAppInfo
can’t be relied on 100% as it’s not frozen.
function getProduct() {
// only works on Gecko 1.8 and higher
if (‘nsIChromeRegistrySea’ in Components.interfaces) {
return ‘SeaMonkey/’+
Components.classes[‘@mozilla.org/network/io-service;1’]
.getService(Components.interfaces.nsIIOService)
.getProtocolHandler(‘http’)
.QueryInterface(Components.interfaces.nsIHttpProtocolHandler).misc.substring(3);
}
// Firefox < 1.0+
else if (navigator.vendor != ”){
return window.navigator.vendor+‘/’+window.navigator.vendorSub;
}
// Firefox 1.0+
try {
var prefs = Components.classes["@mozilla.org/preferences-service;1"].
getService(Components.interfaces.nsIPrefService);
return prefs.getCharPref("general.useragent.extra.firefox");
}
catch(ex) {
return "Unknown";
}
}
3 replies on “Wanted: ProductName/Version”
Here’s a function from Forumzilla that might help. It uses nsIXULAppInfo on Aviary 1.1 apps, the app.id preference on Aviary 1.0 apps, and assumes Seamonkey if neither value is available. It’s designed to distinguish between Seamonkey and Thunderbird but should be easily modifiable to determine if it’s running in Firefox or some other XUL app.
*Edit:* robert 5/20/05 3:34 – parse code for readability.
doh! you all make firefox. and you can’t even get your own product’s version number. So much for F/oss.
The PasteIP extension seems to get it right, in Ff at least so maybe there is some magic there???