Search code examples
google-chromefirefoxnpapi

How to detect first loading of NPAPI plugin/Extension in firefox and chrome


I want to detect first loading of NPAPI plugin/extension. Which event should i handle in extension/plugin.


Solution

  • I found the solution.

    My requirement is i want inform the NPAPI plugin when browser starts.I am having my extension and NPAPI plugin.

    Chrome Solution:

    For chrome background_helper.js loads only once when new instance of chrome gets started. It will not reload on new page or new window.

    Firefox solution: On Firefox window.load gets called when new windows gets opened so i have added code in window.load event handler as follows.

    var Application = Components.classes["@mozilla.org/fuel/application;1"].getService(Components.interfaces.fuelIApplication);
    
    var myExt= {
      onLoad: function() {
        var windowsArray = Application.windows;
        if(windowsArray.length == 1 && gBrowser.browsers.length == 1)
        {
           alert('FireFox started');
        }
      },
    };
    
    window.addEventListener('load', myExt.onLoad, false);
    

    Here gBrowser is golbal object gBrowser.browsers.length wil give tab count.