Identify requests coming from PageWorker

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 21:04:03

问题


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



来源:https://stackoverflow.com/questions/20855939/identify-requests-coming-from-pageworker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!