多次执行注入脚本

发布于 2024-09-08 22:26:09 字数 370 浏览 5 评论 0原文

我已阅读文档并理解这是预期的:

脚本被注入到顶级页面和任何具有 HTML 源的子页面中,例如 iframe。不要假设每个浏览器选项卡只有一个脚本实例。

不过,我想知道:

  1. 除了 iframe 之外,还有哪些其他元素具有“HTML 源”(图像?对象?)? “HTML 源代码”这个术语对我来说含糊不清,令人不安。
  2. 有没有办法检测哪个元素正在执行脚本?

按照建议,我已通过确定 window === window.top 过滤掉了 iframe,但其他元素仍在执行脚本,并且执行次数比我多很多想要。

谢谢。

I've read the documentation and understand that this is to be expected:

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:

  1. Other than iframes, what other elements have "HTML sources" (images? objects?)? The term "HTML sources" is uncomfortably vague to my ears.
  2. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

才能让你更想念 2024-09-15 22:26:09

我回答自己的问题确实是我自己的错,因为我没有在问题中提供足够的信息。在我看来,我当时不知道我提供的信息太少了。

无论如何,在寻找解决方案的过程中,我在 Apple 的开发论坛上提出了一个问题< /a> 并包含以下关键信息:

  • 脚本中的所有内容都发生在 documentbeforeload 事件上(或者应该发生)。

我了解到的是 beforeload 事件仅针对文档中的子资源触发。不适用于文档(或窗口)本身。我删除了事件处理程序并确保该脚本被应用为启动脚本(确实如此)。我已经将窗口作为顶部窗口进行了测试,所以我被覆盖了。现在我的注入脚本只触发一次。

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 the document (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.

我的痛♀有谁懂 2024-09-15 22:26:09

其他 HTML 源可能是框架或对象标签(带有 HTML 内容)。我不认为它可以是其他任何东西。然而,据我所知,它们也应该用 window === window.top 过滤掉。尝试使用 console.log document.location 变量来查看哪个 URL 运行您注入的脚本,也许您可​​以找到加载它们的内容。

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.loging the document.location variable to see which URL runs your injected script, and maybe you can find what loads them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文