跨原产地问题与iFrame chrome扩展
Cross-Origin issue with iFrame for chrome extension
我正试图在Google Hangouts中编写一个自动拨号的chrome扩展,这样我就不必为每次会议输入我的会议桥号码。如果他们也能得救就好了……无论如何,我有一个概念,但我正试图解决一个跨源问题。
当您在Google Hangouts中拨打电话时,您可以从联系人页面开始输入您要拨打的号码。当你按回车键或点击"拨打电话"时,拨号器就会被加载到iFrame中。在我的chrome扩展,我能够得到一个参考的iFrame,但框架是在域"plus.google.com",我的脚本是从"hangouts.google.com"访问。
我知道它们都在google.com父域下,所以我试图让我的chrome扩展访问框架,以便在框架的contentWindow内的dialer按钮上执行。click()。
在我的内容脚本在chrome扩展,我选择从父页iframe元素,并设置为一个变量称为iframe。
var iframe = $("div iframe")[0];
我可以设置
document.domain = "google.com";
没有问题,但是当我尝试执行
时iframe.contentWindow.document.domain = "google.com";
我得到
content.js:3 Uncaught SecurityError: Blocked a frame with origin
"https://hangouts.google.com" from accessing a frame with origin
"https://plus.google.com". The frame requesting access set "document.domain" to
"google.com", but the frame being accessed did not. Both must set
"document.domain" to the same value to allow access.
我试过放松扩展中的内容安全策略,但也许我做得不对:
"content_security_policy": "script-src 'self' https://google.com; object-src 'self'",
"permissions": [
"http://*/",
"tabs"
]
我有办法绕过这个吗?
在这种情况下,增加权限或放松CSP是没有用的。
您需要在iframe中使用第二个内容脚本实例来跨域操作它的文档。
确保在你的内容脚本中注入"all_frames": true
。
您可以使用iframe.contentWindow.postMessage
在内容脚本之间进行通信
相关文章:
- chrome扩展中的navigator.geolocation.getCurrentPosition
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- chrome扩展更改主机/域警告
- 如何在chrome扩展中重定向到html页面
- Chrome扩展没有't在重新加载之前考虑期权价值
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- 从选项页面更新chrome扩展清单权限
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- Chrome扩展:遍历不同的页面并收集数据
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- 可以从Chrome扩展修改窗口对象吗
- 从popup.js|Chrome扩展访问DOM
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 在Chrome扩展内部输出Google API调用
- 检查是否存在使用chrome扩展的javascript库
- 从Chrome扩展访问Google Cloud SQL数据库
- Chrome扩展,Chrome.tabs.query的结果未定义
- 为tweet构建chrome扩展
- 在chrome扩展中使用AJAX获取目录中的文件数