我正在尝试从Chrome扩展程序访问iframe,但出现以下错误
Uncaught DOMException: Blocked a frame with origin "https://<website>" from accessing a cross-origin frame.
at HTMLDivElement.<anonymous> (chrome-extension://ijlbgginkemmeidmhfhbgbbeiloofged/js/button.js:51:28)
清单:
{
"author": [{
"name": "sjpcl"
}],
"manifest_version": 2,
"name": "shocko",
"description": "extension",
"version": "1.0",
"permissions": [
"activeTab",
"storage",
"tabs",
"*://*/"
],
"background":{
"scripts" : ["background.js"]
},
"content_scripts": [
{
"matches": ["http://*/*","<all_urls>","https://*/*"],
"js": ["js/button.js","jquery.js","try.js" ],
"css": ["css/style.css"],
"all_frames": true
}
]
}
错误代码在这里:
button.js:
var iframe=document.getElementById("uploader_iframe");
alert(iframe.contentWindow.document.getElementsByTagName("head").length);
我在同一页面的另一个 iframe上使用了以下代码,但没有收到错误消息:
var iframe=document.getElementsByClassName("ifrm")[1];
alert(iframe.contentWindow.document.getElementsByTagName("head").length);
可能是什么问题?