如何过滤附加 SDK 扩展中的 iframe?
主要问题是我的扩展正在加载到目标网页上的每个 iframe 中。它还放置了出现在 iframe 内的按钮。我想让他们消失。窗口和文档对象显示为父级的窗口和文档对象。因此,无法检查文档位置,因为它显示的是父级的位置而不是 iframe 的位置。
The main problem is that my extension is loading into every iframes on a target webpage. It puts buttons that appear inside the iframes as well. I want them to disappear. The window and document objects are shown as the parent's window and document objects. So it's impossible to check the document location for example because it shows the parent's location instead of the iframe's location.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以编写一个使用
@noframes
元数据标头键的用户脚本,并将用户脚本包含到您的 Jetpack 中:此插件 SDK 的用户脚本包。编写用户脚本也比编写页面 Mod 容易得多。
You could write a user script which uses the
@noframes
metadata header key and include the user script in to your Jetpack with this user script package for the addon sdk.Writing user scripts is much easier than writing Page Mods too.
编辑:现在(附加 SDK 版本 1.11 已发布)
pagemod
支持您正在寻找的内容。 参见文档和新的attachTo
选项。以下信息已过时(如果您针对 Add-on SDK 1.10 或上一篇:
不幸的是,
pagemod
将脚本注入到页面的所有框架中,而不是像使用 Chrome 的内容脚本那样在顶部框架中每个页面注入一次。 但是,如果您确实想在每个页面的顶部框架上注入一次脚本,您必须使用
选项卡
<。使用此解决方案,您的脚本仅在有时才会被注入。下面我提供了从
pagemod
移植到tabs
的示例,使所有消息接收系统都可以轻松修改。如果您不仅需要接收消息,还需要使用相同的port
对象发送消息。当我们位于 youtube.com 域中时,脚本就会被注入:旧 pagemod 方式:
新标签方式:
Edit: now (Add-on SDK version 1.11 released)
pagemod
supports what you are looking for. See the docs and the newattachTo
option.The following information is outdated (can be used if you build against Add-on SDK 1.10 or previous:
Unfortunately
pagemod
injects your script in all the frames of the page, and not just once per page on the top frame as what you achieve with Chrome's content scripts. Of course, there are workarounds for stopping the execution of the script (see the other answers).But if you really want to inject your script only once per page, on the top frame, you have to use
tabs
. With this solution you script only gets injected when it has to.Bellow I provide and example for porting from
pagemod
totabs
, keeping all the message reception system withport
working. It can easily be modified if you need to not just receive, but also send messages using that sameport
object. The script gets injected when we are in the domain youtube.com:Old pagemod way:
New tabs way:
一种解决方法是在内容脚本中添加类似的内容:
内容脚本仍将添加到每个页面,但这是对 iFrame 的相对简单且轻量级的检查。
One workaround is to put something like this in your content script:
The content script will still be added to every page, but it's a relatively simple and lightweight check for iFrames.