【问题标题】:Chrome Uncaught Error: SECURITY_ERR: DOM Exception 18 when trying to XHR a file in a chrome extensionChrome 未捕获错误:SECURITY_ERR: DOM Exception 18 尝试 XHR chrome 扩展中的文件时
【发布时间】:2012-08-30 14:23:29
【问题描述】:

我正在尝试请求 chrome 扩展清单文件(我自己的扩展)

// MAKE MANIFEST FILE AVAILABLE
chrome.manifest = (function() {
    var manifestObject = false;
    var xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4) {
            manifestObject = JSON.parse(xhr.responseText);
        }
    };
    xhr.open("GET", chrome.extension.getURL('/manifest.json'), false);
    try {
        xhr.send();
    } catch(e) {
        log('Couldn\'t load manifest.json');
    }
    return manifestObject;
})();

但我得到一个错误:

未捕获的错误:SECURITY_ERR:DOM 异常 18(匿名 函数)cm_background.js:46(匿名函数)

第 46 行是 xhr.open("GET", chrome.extension.getURL('/manifest.json'), false);

允许我执行此操作的适当的清单安全策略是什么,或替代的安全方式是什么?

更新

清单文件

{
  "manifest_version": 2,
  "name": "A plugin",
  "version":"1.3.6",
  "background": {
    "page":"cm_background.html"
  },
  "page_action": {
    "default_icon": "logo.png",
    "default_title": "A plugin",
    "default_popup": "cm_popup.html"
  },
  "content_scripts": [
    {
      "matches": ["http://mail.google.com/*", "https://mail.google.com/*"],
      "js": ["jquery.js",
             "underscore.js",
             "sha256.js",
             "utils.js",
             "cm_content_script.js",
             "cm_content_ui_control.js",
             "cm_first_install.js"]
    }
  ],
  "permissions" : [
    "tabs",
    "http://mail.google.com/*",
    "https://mail.google.com/*",
    "http://*/*",
    "https://*/*",
    "chrome-extension://*/*"
  ],
  "web_accessible_resources": [
    "manifest.json",
    "cm_first_install.js",
    "jquery.js",
    "cm_signature_editor.css",
    "cm_signature_editor.html"
  ],
  "content_security_policy": "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src *;"
}

【问题讨论】:

  • 您的清单看起来如何?

标签: google-chrome-extension


【解决方案1】:

此方法是否为您提供所需的信息?

chrome.app.getDetails()

它似乎没有记录在 API 中,但它会返回清单中的大部分数据。

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 2011-07-27
    • 2011-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-12
    • 1970-01-01
    • 2012-07-02
    相关资源
    最近更新 更多