开发者

Using addProgressListener and onStatusChange to obtain DNS lookup times for pages

I'm trying to add functionality to a firefox extension to time how long it takes a webpage to perform DNS lookup. Looking at Firebug, I figured it's possible to do so by adding a web progress listener to the browser object and listening for events.

First I register an event listener when a page is loaded:

window.addEventListener("load", function(e) { myObj.onLoad(e); }, false);

Inside myObj.onLoad() I register my web progress listener as such:

 gBrowser.addProgressListener(this, Components.interfaces.nsIWebProgress.NOTIFY_ALL);

Finally I implement 'onStatusChange' inside myObj, along with QueryInterface and others:

o开发者_高级运维nStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) {
    this.logInfo("onStatusChange: " + aMessage + ". Time = " + (new Date().getTime()));
}

However, when onStatusChange is called, aStatus is always 0 even though aMessage displays the correct event. I've spent hours trying to figure this out. Any ideas why??

Also it seems that onStatusChange with status of 'Ci.nsISocketTransport.STATUS_RESOLVING' is only being called on some components, without being called for others, even though they may have a different domain name that needs to be translated and the DNS has not been cached. Need help plz!


If you attach a progress listener to the tabbed browser you only get a filtered view of progress events. You might find that you need to attach your progress listener to the inner browser instead. (If you want to watch multiple tabs/windows you might find it better to attach your progress listener to the window itself, or, for a service, to the root document loader.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜