3

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

manifest.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) によってブロックされていると思います。

解決策はありますか?

4

3 に答える 3

4

index.jsは、manifest.jsonファイルで定義されているようにサンドボックス化されます。
サンドボックス化されたページは拡張機能またはアプリAPIにアクセスできません」
そのため、localstorageにアクセスできません。
サンドボックスを削除するか、サンドボックス化されたページにhttps://github.com/jamesmortensen/chrome-sandbox-storageAPIなどを使用します。

于 2013-01-18T07:56:17.837 に答える
4

答えは 2 つあります。

  1. このようにタグに追加ng-cspします。このSOの回答を参照してください<html><html ng-csp ng-app="AngularAppName">
  2. manifest.jsonこの行をファイルに追加します

"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self' "

于 2013-02-19T07:24:59.090 に答える
0

コードの問題

これらは、これまでに共有されたコードで見られる問題の一部です!.

  • あなたは、として、およびでindex.html使用されています。機能的に正しくありません。何を開発したいですか?default_popupweb_accessible_resourcessandbox Pages
  • なぜangular.min.jsサンドボックスの場所に置きたいのですか?
  • index.jsによって使用されます。使用される場合はindex.html、明示的にリストする必要はありません。
  • ストレージはドメインごとのオブジェクトであり、localstorageサンドボックスや他のページとは異なります。
于 2013-01-19T10:50:51.773 に答える