【问题标题】:Uncaught DOMException: Blocked a frame with origin Chrome extensionUncaught DOMException: Blocked a frame with origin Chrome extension
【发布时间】:2019-01-19 16:15:07
【问题描述】:

我正在尝试创建一个 chrome 扩展程序。 应用程序的目标: 打开新的弹出窗口并编辑内容和 html 但它不起作用 它在控制台中向我显示此错误:

未捕获的 DOMException:阻止了来源为“chrome-extension://pjnjcefdmacabhjhkkggfbcbdalfannl”的框架访问跨域框架。

ma​​nifest.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;

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

有什么帮助吗?

【问题讨论】:

标签: javascript json google-chrome-extension manifest


【解决方案1】:

您可以向它提供无意义的目标网站查询字符串参数来传递您的参数,并创建另一个内容脚本,而不是从当前内容脚本操作新窗口 "https://mail.google.*/*?myparam*"
在这个新的内容脚本中,您可以从查询字符串中获取参数并将它们设置到字段中而不会出现错误。

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

【讨论】:

  • 首先,感谢您的回复。其实这个我也不是很明白,我试着这样做:myWindow = window.open("test.com/…, '', 'width=900,height=500'); myWindow.getElementById('elementId' ).setAttribute('value', getParameter(1)); function getParameter(a) { var tmp = []; tmp = location.search .substr(1) .split("&") return tmp[a].split ('=')[1]; } 但它不起作用,请给我解释一下。
猜你喜欢
  • 2019-07-19
  • 1970-01-01
  • 1970-01-01
  • 2016-04-15
  • 2018-12-12
  • 1970-01-01
  • 2017-01-13
  • 2020-12-10
相关资源
最近更新 更多