javascript - Uncaught DOMException: Blocked a frame with origin Chrome extension
问题描述
我正在尝试创建一个 chrome 扩展。该应用程序的objectif:打开新的弹出窗口并编辑内容和html,但它不起作用它在控制台中向我显示此错误:
未捕获的 DOMException:阻止了具有来源“chrome-extension://pjnjcefdmacabhjhkkggfbcbdalfannl”的框架访问跨域框架。
清单.json:
{
"manifest_version": 2,
"name": "Title!",
"description": "Description...",
"version": "1.0",
"browser_action": {
"default_icon": "images/email.png",
"default_popup": "popup.html",
"default_title": "Title",
"matches": ["*://*.*/*"]
},
"permissions": [
"webRequest",
"storage",
"*://*.*.*/*",
"activeTab"
],
"chrome_url_overrides": {
"newtab" : "popup.html"
},
"content_scripts": [{
"matches": [ "*://*.*/*" ],
"js": [ "script.js" ],
"all_frames": true
}]
}
script.js:(错误部分)
myWindow = window.open("https://gmail.com", "", "width=900, height=500");
myWindow.document.getElementById("elementId1").value = variable1;
myWindow.document.getElementById("elementId2").value = variable2;
我无法获取值或更改它们,我尝试了很多网址,但它显示相同的错误
请问有什么帮助吗?
解决方案
您可以为目标网站查询字符串参数传递您的参数并创建另一个内容脚本,而不是从当前内容脚本中操作一个新窗口,而不是include_globs
在
"https://mail.google.*/*?myparam*"
这个新的内容脚本中,您可以从查询字符串中获取参数并将它们设置为没有错误的字段。
PS:如果目标网站删除了未知的查询参数,您可以尝试锚定。
推荐阅读
- java - Java 拒绝检测任何类库
- c# - How to check if member A paid for month January in 2019 and if he did disable option to make payment again in 2019 for monthJanuary?
- reactjs - 如何在 React Native 中从孙子到祖父母,然后再回到祖父母的孩子
- swift - 如何修复转义关闭?错误是:转换非转义值可能允许它转义
- reactjs - 打字稿对象文字可能只指定已知属性错误
- html - 子菜单出现时如何向下移动最后一个div
- android - Can't return current keyboard language
- java - 使用默认服务帐户的 Bigquery 插入作业
- javascript - 如何在 HTML 元素而不是 JavaScript 警报中显示 JavaScript 函数的输出?
- javascript - 我正在尝试从最低级别组件的输入字段中捕获数据