在Chrome 45.0.2454.101使用扩展名访问跨域iframe的文档
问题说明
我使用Chrome扩展程序中的内容脚本来访问跨域iframe中的文档,使用以下代码:
I am using a content script in a Chrome extension to access a document in a cross domain iframe, using this code:
document.querySelector('iframe').contentWindow.document
直到我升级到最新版本的谷歌浏览器(45.0.2454.101 64位),当访问iframe时报告以下安全错误:
This worked fine until I upgraded to the latest version of Google Chrome (45.0.2454.101 64-bit), which reports the following security error when accessing the iframe:
Uncaught SecurityError: Blocked a frame with origin
"http://www.miercn.com" from accessing a frame with origin
"http://pos.百度.com". Protocols, domains, and ports must match.
这个版本的Chrome有什么变化,以及如何解决这个问题?
What changed in this version of Chrome and how to resolve this problem?
我的Chrome版本:
My Chrome version:
Google Chrome 45.0.2454.101(正式版本)(64位)
修订版本3b3c00f2d95c45cca18ab944acced413fb759311-refs / branch-heads / 2454 @ {#502}
操作系统Mac OS X Blink 537.36
(@ 3b3c00f2d95c45cca18ab944acced413fb759311)JavaScript V8 4.5.103.35
Flash 19.0.0.185用户代理Mozilla / 5.0(Macintosh;英特尔Mac OS X 10_9_4)
AppleWebKit / 537.36(KHTML,如Gecko)Chrome / 45.0.2454.101
Safari / 537.36命令行/ Applications / Google
Chrome。 app / Contents / MacOS / Google Chrome - 启用 - 基础
- 启用-avfoundation - 标记 - 开关 - 开始 - 标记 - 开关 - 结束
Google Chrome 45.0.2454.101 (正式版本) (64 位) 修订版本 3b3c00f2d95c45cca18ab944acced413fb759311-refs/branch-heads/2454@{#502} 操作系统 Mac OS X Blink 537.36 (@3b3c00f2d95c45cca18ab944acced413fb759311) JavaScript V8 4.5.103.35 Flash 19.0.0.185 用户代理 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36 命令行 /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --enable-avfoundation --enable-avfoundation --flag-switches-begin --flag-switches-end
正确答案
您必须使用跨域消息传递通过 postMessage 。
以及为了让主页上的内容脚本与注入到iframe中的内容脚本进行通信,内容脚本应该注入 all frames :
$ b
And in order for your content script on the main page to communicate with the content script injected into the iframe, the content script should be injected in all frames:
"content_scripts": [{
"matches": ["<all_urls>"],
"js": ["content.js"],
"all_frames": true
}],
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcgfcci
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
希伯来语的空格句子标记化错误
it1352 06-22