首页 > 解决方案 > 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;

我无法获取值或更改它们,我尝试了很多网址,但它显示相同的错误

请问有什么帮助吗?

标签: javascriptjsongoogle-chrome-extensionmanifest

解决方案


您可以为目标网站查询字符串参数传递您的参数并创建另一个内容脚本,而不是从当前内容脚本中操作一个新窗口,而不是include_globs"https://mail.google.*/*?myparam*"
这个新的内容脚本中,您可以从查询字符串中获取参数并将它们设置为没有错误的字段。

PS:如果目标网站删除了未知的查询参数,您可以尝试锚定。


推荐阅读