javascript - 在 Chrome 扩展中使用 AngularJS

标签 javascript google-chrome-extension angularjs

我想在 Chrome 扩展中使用 AngularJS,但出现如下错误:

Error: SECURITY_ERR: DOM Exception 18
Error: An attempt was made to break through the security policy of the user agent.
    at new listConnection

list .json :

 {
  "name": "Chrome auditor connection",
  "version": "1",
  "icons": { "48": "icone.png",
            "128": "icone.png" },
  "description": "Chrome-auditor-connection is an extension for Google Chrome browser. It ensures that nobody connects to your browser with your profile.",
  "background": {
    "scripts": [
      "chrome_ex_oauthsimple.js",
      "chrome_ex_oauth.js",
      "background.js"
    ]
  },
  "browser_action": {
    "default_title": "Chrome auditor connection",
    "default_icon": "icone.png",
    "default_popup": "index.html"
  },
  "permissions": [
    "storage"
  ],
  "web_accessible_resources": ["index.html"],
  "sandbox": {
     "pages": ["index.html","index.js","angular.min.js"]
  },
  "manifest_version": 2
}

index.js :

function listConnection( $scope) {      
    $scope.connections = JSON.parse(localStorage['connectionHistory']);
}

我认为 JSON.parse() 被 Chrome“内容安全策略”(CSP) 阻止了。

有什么解决办法吗?

最佳答案

您的 index.js 已按照 manifest.json 文件中的定义进行沙盒处理。
sandboxed 页面将无法访问扩展程序或应用程序 API”
所以它不能访问本地存储。
删除沙箱或使用类似 https://github.com/jamesmortensen/chrome-sandbox-storageAPI 的东西对于沙盒页面。

关于javascript - 在 Chrome 扩展中使用 AngularJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14390018/

相关文章:

javascript - Google Cloud Pub/Sub 在消息吞吐量低时触发高延迟

php - jquery if 语句和 hasClass?

javascript - 无法从 chrome.storage.sync.get 检索值

javascript - 新窗口中的 Angular JS 空 pdf

javascript - Angularjs $http 请求缓存在浏览器后退按钮上

javascript - 如何将 Backbonejs 用于大型可扩展应用程序?

javascript - 加载时文本框默认文本,焦点时文本框为空

javascript - 用于自动填写 Angular 创建的用户密码表单的内容脚本

javascript - 在回调中使用cursor.continue()

angularjs - AngularJS 中 $broadcast()、$emit() 和 $on() 的用法