使用addProgressListener和onStatusChange获取页面的DNS查找时间

发布于 2024-10-30 17:55:27 字数 861 浏览 2 评论 0原文

我正在尝试向 Firefox 扩展添加功能,以计算网页执行 DNS 查找所需的时间。看看 Firebug,我认为可以通过向浏览器对象添加 Web 进度侦听器并侦听事件来实现此目的。

首先,我在加载页面时注册一个事件侦听器:

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

在 myObj.onLoad() 内部,我这样注册我的 Web 进度侦听器:

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

最后,我在 myObj 内部实现“onStatusChange”,以及 QueryInterface 和其他内容:

onStatusChange: function(aWebProgress, aRequest, aStatus, aMessage) {
    this.logInfo("onStatusChange: " + aMessage + ". Time = " + (new Date().getTime()));
}

但是,当调用 onStatusChange 时,aStatus即使 aMessage 显示正确的事件,也始终为 0。我花了几个小时试图弄清楚这一点。有什么想法为什么吗?

此外,状态为“Ci.nsISocketTransport.STATUS_RESOLVING”的 onStatusChange 似乎仅在某些组件上被调用,而不会被其他组件调用,即使它们可能具有需要转换的不同域名并且 DNS 尚未缓存。需要帮助请!

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:

onStatusChange: 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑饮青盏花 2024-11-06 17:55:27

如果将进度侦听器附加到选项卡式浏览器,您只能获得进度事件的筛选视图。您可能会发现需要将进度侦听器附加到内部浏览器。 (如果您想观看多个选项卡/窗口,您可能会发现最好将进度侦听器附加到窗口本身,或者对于服务,附加到根文档加载器。)

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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文