What event-listeners can I use to identify requests originating from the hiddenDOMWindow (or an iframe within it) in a firefox-addon? I need to do this BEFORE the request has been sent, in the "http-on-modify-request" event, for example.
What I've tried:
- register for the global "http-on-modify-request"; but I can't distinguish the source window
- add listener to the hiddenDOMWindow itself; but I can't find any before-load-event
- add listener to the hiddenDOMWindow.document; no before-load-event
- add listener to the created hiddenDOMWindow.document.iframe; no before-load-event
First, you need to get a
DOMWindow
from annsIChannel
:Now that you got a
DOMWindow
, you need to find the top level window for thatDOMWindow
, which is not really intuitive:Now, lets craft and install the observer, bringing all together:
It should be noted that not all requests are
nsIChannel
and not allnsIChannel
actually have aDOMWindow
or realloadGroup
associated (e.g. background requests), hence all thosetry catch
blocks.Also, don't forget to remove the observer again at some point, which I skipped. ;)
And lastly, here is some code to actually test this (I ran the whole thing as a Scratchpad on an about:newtab tab, which happens to have chrome privileges just like add-ons):