在 Chrome 扩展中创建隐藏的 iframe
是否可以在 google-chrome 扩展中的 background.html 页面上创建一个 iframe 并让它向网站发出请求?我不确定该扩展程序到底是如何工作的。 chrome 会自动忽略所有显示标签还是会以不可见的方式运行它?
Is it possible to create an iframe on the background.html page in a google-chrome extension and have it make the request to the website? I am not sure how exactly the extension works. Does chrome automatically ignore all display tags or will it run it invisibly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它会正确加载 iframe,但我认为由于同源限制,不可能从 iframe 中读取任何内容。例如,此后台脚本失败:
错误:“不安全的 JavaScript 尝试访问 URL http://www.google.com/ 来自 URL chrome-extension://elbpnmnjddamdmjmdnmhankaimaldhmf/background.html 的框架,域、协议和端口必须匹配。”
It will load the iframe all right, but I don't think it's possible to read anything out of an iframe due to same-origin restrictions. For example, this background script fails:
with error: "Unsafe JavaScript attempt to access frame with URL http://www.google.com/ from frame with URL chrome-extension://elbpnmnjddamdmjmdnmhankaimaldhmf/background.html. Domains, protocols and ports must match."
我的理解是,扩展程序的背景页面永远不会显示,但它应该按预期“运行”(例如
img
标记的src
属性将导致图像数据被获取)。我刚开始实施扩展程序,但架构概述似乎暗示这和我见过的样品一样。您可以单击扩展控制面板中的background.html 链接并检查source/dom/etc。
My understanding is that the background page of an extension is never displayed, but it should "run" as expected (e.g.
src
attribute of animg
tag will cause the image data to be fetched). I'm new to implementing extensions, but the architecture overview seems to imply this, as do the samples I've seen.You can click on the link to background.html in the extensions control panel and inspect the source/dom/etc.
经过我自己的测试:显然 google-chrome 确实运行 iframe。它只是不会显示它们。
After testing myself: Apparently google-chrome does run iframes. It just wont display them.