识别来自PageWorker的请求 [英] Identify requests coming from 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
。
你可以说,一个请求不是来自页面工作者,当它不是来自 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 thehiddenWindow
(technically, insdk/addon/window
, which creates a hidden window in thehiddenWindow
). ThehiddenWindow
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 WeakMap
s 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屋!