1. No Profile Picture
    The Monk that is Fat.
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Rep Power

    Why is my init() not running? (on Firefox extension install)

    I keep returning to this problem, and keep on failing to solve it.

    I've read tens of pages describing how to do it, and looked at answers such as How can I make my Firefox extension toolbar button appear automatically? on here, but I just can't get this right.

    I understand the concept of what I need to do, but whenever I try I usually end up breaking my JavaScript entirely.

    What I want to achieve is the recommended process of adding the toolbar button on install / update but only on first run/install.

    My extension consists of:
    • chrome.manifest and install.rdf in the extension root directory.
    • chrome folder which contains the other elements (extensionName.js, extensionName.png, extensionName.xul, extensionName.css and icon.png).
    • prefs.js in defaults/preferences with the extensions.MyExtensionNameButton.firstRunDone value being set to false.

    The extension works exactly as required (it includes a toolbar button and right-click context menu items).

    My extensionName.js file contains the following (with the actual routines trimmed out):

    objMyExtensionNameButton = {
        // functions that are called by the .xul are in here,
        init : function() {
          var firstRunPref = "extensions.MyExtensionNameButton.firstRunDone";
          alert("init function run");
          if (!Application.prefs.getValue(firstRunPref)) {
            Application.prefs.setValue(firstRunPref, true);
            // all the rest of the first run code goes here.
            alert("this is the first run");
          } else {
            alert("this is NOT the first run");
    window.top.addEventListener("load", function() { objMyExtensionNameButton.init(); }, false);
    I've also tried moving the init function out of the objMyExtensionNameButton object and calling it directly, but it just doesn't seem to want to fire.

    At the moment the button and right click menus work as expected, but I never see the alerts in the init() function so I don't believe that is ever running. The extensions.MyExtensionNameButton.firstRunDone value is never being set to true either, which shoud lbe being done by the same init() function. (I've checked in pref.js under my user profile and in about:config and the preference value stays false).

    Once I get this bit working I'll use https://developer.mozilla.org/en-US/...ton_by_default to actually add the button to the toolbar, but I need to get the user-friendly bits working first.


    Last edited by fatmonk; December 10th, 2013 at 06:29 AM. Reason: Updating info.

IMN logo majestic logo threadwatch logo seochat tools logo