问题
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;
...
});
回答1:
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.
来源:https://stackoverflow.com/questions/20855939/identify-requests-coming-from-pageworker