0

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);
}
4

1 回答 1

0

使用选项卡进度侦听器时,您可以使用onStateChange.

不过,我不太明白您为什么不能使用DOMContentLoaded...... 有一些 API 可以将事件映射回window( event.originalTarget.defaultView) 和/或document( event.originalTarget.ownerDocument)。

还有<tabbrowser>.getBrowserForDocument(document)和朋友。

于 2013-09-20T21:00:18.707 回答