Frage

I am creating simple plugin to catch http-request and save information about it to files. Saving module works and catching module also. All http request belonging to each window are saving to separate files. For example all http request from any tab of window 1 saving to file 1.txt, from window 2 saving to file 2.txt etc. But for now I have problem, because request from window 2,3, ... saving also to previous files. I mean:

  1. all http requests from window 1 saves to 1.txt (it's ok)
  2. all http requests from window 2 saves to 1.txt and 2.txt
  3. all http requests from window 3 saves to 1.txt, 2.txt and 3.txt

I am using observer, but for test I was using eventListener for click, any it works perfect. Click from window x was saving only for file x. Any idea, what can be wrong?

War es hilfreich?

Lösung

Observers are global, not per window. When you register them from an overlay script, you'll get one observer for each window, and each of these observers will get notified for all http connections, no matter what window the request originated from (remember: observers are global). Oh, and each observer will also get each notified on each request that doesn't have any associated window (e.g. safe-browsing request refreshes, other components, other add-ons doing requests from their code modules).

You should do the following:

  • Rewrite your code to only register exactly one observer for the whole application. Easiest way to do this is to implement it in a code module.
  • Have the observer figure out the DOMWindow, if any, top level window, if any, and map that to a specific file. I already gave some code in another answer mapping a request to a DOMWindow and top level window in a http observer.
  • How to map a request to a window and file is up to you in the end. You could register each top level window with your code module, and your code module would then generate an id/file name for each window and then in observe use that information to map the request window to the id and file, ...
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top