I am using the onProgressChange callback of tabsProgressListener in my firefox extension. I am using this callback to track the progress of page load so that I am can use this information to inject my contentscripts into the page.
However, sometimes the progressListener does not always give the completion status.
I cannot use the onPageLoad sample mentioned in this web site because I need a handle on the tab to independently track and load the scripts even when the tab is switched.
I am not clear on why this is happening. Please help.
If there is any other way of doing it in the onPageLoad where I can access the tab and independently track and inject script into each of the tabs even on switching the tabs, that would also do.
Here is the snippet of the code I have implemented:
var tabsProgressListener = {
onProgressChange: function( aBrowser,
aWebProgress,
aRequest,
aCurSelfProgress,
aMaxSelfProgress,
aCurTotalProgress,
aMaxTotalProgress
) {
Components.utils.reportError("onProgressChange: " + aCurTotalProgress + "/" + aMaxTotalProgress);
if(aCurTotalProgress === aMaxTotalProgress) {
onPageLoad(aBrowser);
}
}
};
gBrowser.addTabsProgressListener(tabsProgressListener);
function onPageLoad(context) {
var loader = Components.classes[ "@mozilla.org/moz/jssubscript-loader;1" ]
.getService( Components.interfaces.mozIJSSubScriptLoader );
loader.loadSubScript("chrome://signonex/content/script1.js", context);
loader.loadSubScript("chrome://signonex/content/script2.js", context);
loader.loadSubScript("chrome://signonex/content/script3.js", context);
}