识别来自PageWorker的请求 [英] Identify requests coming from PageWorker

查看:160
本文介绍了识别来自PageWorker的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从http-on-modify-request事件中识别哪些请求来自PageWorker对象,而不是来自可见标签/窗口的请求?注意:由于重定向和子资源,这里的URL与pageWorkers的contentURL属性不是同一个URL。



$ b (http-on-modify-request,函数(e){

var httpChannel = e.subject.QueryInterface(Ci.nsIHttpChannel),
url = httpChannel.URI.spec,
origUrl = httpChannel.originalURI.spec;

...
});


解决方案

page-worker 常规请求。



目前,页面工作者是这样实现的:




  • SDK本质上​​在 hiddenWindow中创建一个< iframe> (技术上,在 sdk / addon / window 中,它在 hiddenWindow )。 Mozilla应用程序中的 hiddenWindow 或多或少都是始终存在的顶级XUL或HTML窗口,它们仅仅是隐藏的。 工作页面加载到 iframe

  • 页面工作人员然后将在 iframe



可以和隐藏窗口内的文档。然后识别请求或相关文档是否属于根据代码判断, page-worker ,更不用说 page-worker 实例了。 SDK本身可以将与请求相关联的文档映射回 page-worker ,因为它保留了一些 WeakMap s不过这是你不能访问的内部资源。



你可以说,一个请求不是来自页面工作者,当它不是来自 hiddenWindow



另外请记住,有大量的请求都不是源自 tab 也不是 page-worker :其他(XUL)窗口,附件,js模块和组件等等。



如果您感兴趣的附加组件创建的 page-worker contentURL 属性应该反映页面加载后的最终URI。


Is it possible, from within the "http-on-modify-request" event, to identify which requests are coming from a PageWorker object, as opposed to those coming from visible tabs/windows?

Note: Because of redirects and subresources, the URL here is NOT the same URL as the pageWorkers contentURL property.

require("sdk/system/events").on("http-on-modify-request", function(e) {

    var httpChannel = e.subject.QueryInterface(Ci.nsIHttpChannel), 
        url = httpChannel.URI.spec, 
        origUrl = httpChannel.originalURI.spec;

    ...         
});  

解决方案

I don't know of any way to actually distinguish page-worker requests from "regular" ones.

Current, page workers are implemented like this:

  • The SDK essentially creates an <iframe> in the hiddenWindow (technically, in sdk/addon/window, which creates a hidden window in the hiddenWindow). The hiddenWindow in mozilla applications is more or less an always-present top-level XUL or HTML window that is simply hidden.
  • The worker page is loaded into that iframe.
  • The page-worker will then operate on the DOM on that iframe.

It is possible to identify requests originating from the hidden window and the document within the hidden window.

But identifying if the request or associated document belongs to a page-worker, let alone which page-worker instance, doesn't seem possible, judging from the code. The SDK itself could map the document associated with a request back to a page-worker, as it keeps some WeakMaps around to do so, but that is internal stuff you cannot access.

You only can say that a request is not coming from a page-worker when it is not coming from the hiddenWindow.

Also, keep in mind that there are tons of requests originating neither from a tab nor page-worker: Other (XUL) windows, add-ons, js modules and components, etc...

If it a page-worker created by your add-on that you're interested in: The contentURL property should reflect the final URI once the page is loaded.

这篇关于识别来自PageWorker的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆