【发布时间】:2015-12-11 15:42:25
【问题描述】:
我有一个包含 iFrame 的页面,它加载不同的网站,并希望能够与 iFrame 的内容进行交互(单击、聚焦、选择、输入值等)。
到目前为止,我可以检查 iFrame 是否已加载,但是一旦尝试执行简单的操作,例如在其中隐藏元素,则什么也没有发生。
manifest.json
{
"manifest_version": 2,
"name": "my Extension",
"version": "0.1",
"content_scripts" : [
{
"matches": [
"http://*.myPage.com/*",
"https://*.iframePage.com/*"
],
"js": ["lib/jquery-2.1.4.min.js", "content.js"]
}
]
}
content.js
console.log('Page Loaded');
var myFrame = $('iframe');
myFrame.ready(function() {
console.log('Frame Loaded');
});
chrome 中也有一条警告说:
Uncaught SecurityError: Blocked a frame with origin "https://www.iframePage.com" from accessing a frame with origin "http://www.myPage.com". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match.
不确定这是否与扩展问题有关。
【问题讨论】:
-
我似乎记得您可以规避扩展清单中的跨源问题 - 或许可以调查一下
-
警告意味着:
http或https使用相同的协议。 -
您是否查看过设置all_frames 并使用消息传递与框架进行通信?
标签: javascript jquery google-chrome iframe google-chrome-extension