Injection Scripts Executing Multiple Times
I've read the documentation and understand that this is to be expect开发者_Python百科ed:
Scripts are injected into the top-level page and any children with HTML sources, such as iframes. Do not assume that there is only one instance of your script per browser tab.
I'm wondering, though:
- Other than iframes, what other elements have "HTML sources" (images? objects?)? The term "HTML sources" is uncomfortably vague to my ears.
- Is there any way to detect which element is executing the script?
I've filtered out iframes by determining that window === window.top
, as recommended, but other elements are still executing the script and it's executing a lot more than I'd like.
Thanks.
It's really my own fault that I'm answering my own question because I didn't really provide enough information in my question. In my defense, I didn't know at the time that I was providing too little information.
Anyway, while traveling down the road to a solution for this, I asked a question on Apple's dev forum and included the following bit of key info:
- Everything in the script occurs on the
beforeload
event of thedocument
(or was supposed to).
What I learned was that the beforeload
event only fires for subresources within the document. Not for the document (or window) itself. I removed the event handler and made sure that the script was applied as a start script (it was). I'd already applied the test for the window as top window so I was covered. Now my injection script only fires once.
Other HTML sources may be frames or object tags (with HTML contents). I don't think it can be anything else. However, to the extent of my knowledge, they should also be filtered off with window === window.top
. Try console.log
ing the document.location
variable to see which URL runs your injected script, and maybe you can find what loads them.
精彩评论