简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM