2012-08-12 51 views
0

我想創建我的第一個Chrome擴展,這裏是我的manifest.json無法解析谷歌鉻擴展CSP錯誤

{ 
    "name": "share2twitter", 
    "version": "0.1", 
    "manifest_version": 2, 
    "browser_action":{ 
     "default_icon": "icon.png", 
     "default_popup": "index.html" 
    }, 
    "background": {"page": "index.html"}, 
    "permissions": [ 
     "https://www.googleapis.com/*", 
     "tabs" 
     ], 
    "content_scripts": [{ 
     "matches": [ "http://*/*", "https://*/*" ], 
     "js": [ "jquery.min.js","index.js" ] 
    }], 
    "content_security_policy": "script-src https://www.googleapis.com/urlshortener/ 'self'; object-src 'self'; connect-src https://www.googleapis.com/" 

} 

https://github.com/kracekumar/share2twitter/blob/master/manifest.json並在調試模式下,我得到了下面的錯誤。

Refused to load script from 'https://www.googleapis.com/urlshortener/v1/url?callback=jQuery17108621194534935057_1344774835421&{%22longUrl%22:%22https://groups.google.com/a/chromium.org/forum/?fromgroups' because of Content-Security-Policy. 

我看着mappy,stackoverflow.com和谷歌官方文檔,沒有任何工作的參考。所以我在這裏要求幫助。

預期行爲: 當我點擊擴展名時,它會嘗試連接到goo.gl網址縮寫並顯示警告框。

回答

1

內容安全策略值中不允許源URL中的路徑。你需要在你的清單以使用此:

"content_security_policy": "script-src https://www.googleapis.com 'self'; object-src 'self'; connect-src https://www.googleapis.com"

A Chromium bug已經提交(並有一些正在進行的工作),在這種情況下,更好的警告。