在Chrome 45.0.2454.101中使用扩展名访问跨域iframe的文档 [英] Accessing the document of a cross domain iframe using an extension in Chrome 45.0.2454.101

查看:312
本文介绍了在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.baidu.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
}],

这篇关于在Chrome 45.0.2454.101中使用扩展名访问跨域iframe的文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆