• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

在Chrome 45.0.2454.101使用扩展名访问跨域iframe的文档

用户头像
it1352
帮助1

问题说明

我使用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

正确答案

#1

您必须使用跨域消息传递通过 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
系列文章
更多 icon
同类精品
更多 icon
继续加载