Firefox extension opens page on installation

I noticed that some Firefox extensions during installation will open a page after restarting the browser, for example, the StumbleUpon toolbar .

This is useful to display update notes and provide the user with some information such as a tutorial.

How do you start to open a new page in the Firefox add-on when you first launch the browser after installation?

+3
source share
2 answers

Although there may be a better way, I don’t know about this ... You can use the settings system to track if this is the first launch / update

Check if preference exists, if not, open the page, create a prefix with the current extension version number. If the preference exists, check it for the current version number of the extension, if they are different, suppose this is an update and open the page. (assuming you want the page to open every time it refreshes)

var prefs = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService); prefs.QueryInterface(Components.interfaces.nsIPrefBranch2); if ((prefs.getPrefType("extensions.yourextensionhere.yourprerference") == PREF_INVALID) || (prefs.getCharPref("extensions.yourextensionhere.yourprerference") != this.version)) { //open page and... prefs.setCharPref("extensions.yourextensionhere.yourprerference",this.version) } 

EDIT .. check version == == instead of = = as it should be

+5
source

I did not work directly with firefox extensions, but I could imagine something like storing a flag (boolean value) in read-only memory (however, you keep the user settings). When the browser launches for the first time after installation, the flag will not be set, so you will display the help page and set the flag. The next time firefox restarts, the flag will already be set, so you won’t open the help page.

If you want it to show the page every time the extension has been updated, save the version instead of the logical one, and each time you start, check if the current version is larger than the current version.

0
source

All Articles