Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Browser Version From Firefox Extension

I have written a Firefox extension and am currently in the process of updating it for Firefox 4 and adding some new features.

Firefox 4 has a great new notification display that I'd quite like to use and have found plenty of documentation on how to use it. However, for anything less than 4 I have created my own notification window with specific styles.

My question is: how can I detect whether I'm using Firefox 4 or not in the javascript for my extension. Or, is there a better way of doing this?

like image 987
Alex Avatar asked Feb 11 '11 09:02

Alex


People also ask

How do I find my Firefox browser version?

On the menu bar, click the Firefox menu and select About Firefox. The About Firefox window will appear. The version number is listed underneath the Firefox name.

How do I view the code of an extension in Firefox?

Extension Metadata menu that appears when you right-click on the extension button. It also adds a context menu item on Firefox and Chrome extension links. The "View source" option opens a new tab with a simple viewer, with the following features: - Download-as-zip and download-as-crx at the upper-right corner.

What is Firefox browser extension?

Extensions are like apps for Firefox. They add features to Firefox to make browsing faster, safer, or just plain fun. See all extensions. Elite ad blockers.

Does Firefox have browser extensions?

Extensions for Firefox are built using the WebExtensions API cross-browser technology. The technology for extensions in Firefox is, to a large extent, compatible with the extension API supported by Chromium-based browsers (such as Google Chrome, Microsoft Edge, Opera, Vivaldi).


1 Answers

You can use nsIXULAppInfo:

var appInfo = Components.classes["@mozilla.org/xre/app-info;1"]
                    .getService(Components.interfaces.nsIXULAppInfo);
// appInfo.version contains the version

You can compare versions with nsIVersionComparator.

Maybe there is a better way, but this definitely works for me.

like image 159
Felix Kling Avatar answered Sep 21 '22 06:09

Felix Kling