我正在製作一個谷歌瀏覽器擴展,我想要使用谷歌地圖。問題是,當我運行我的腳本,然後它給我這個錯誤谷歌地圖api腳本確實由於內容安全策略加載
Refused to load script from 'https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXXXXXXX&sensor=false' because of Content-Security-Policy.
這裏是我的清單文件
{
"name": "Name",
"version": "1.0",
"manifest_version": 2,
"background": {
"scripts": [
"js/script.js"
]
},
"description": "Desc",
"browser_action": {
"default_icon": "images/icon.png",
"default_title": "Title",
"default_popup": "html/popup.html"
},
"permissions": [
"http://*/",
"http://*.google.com/",
"http://localhost/*"
],
"content_security_policy": "script-src 'self' http://google.com; object-src 'self'"
}
而且我將我的劇本是這樣
<script src="../js/libs/jquery.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXXXXX&sensor=false"></script>
<script src="../js/plugins/easing.js"></script>
<script src="../js/script.js"></script>
爲什麼我一次又一次地得到那個錯誤?請幫助...
更新一個
我加入這兩個權限清單文件,但仍然沒有工作
"https://maps.google.com/*",
"https://maps.googleapis.com/*",
更新兩個
我也用這種content_security_policy
"content_security_policy": "default-src 'none'; style-src 'self'; script-src 'self'; connect-src https://maps.googleapis.com; img-src https://maps.google.com"
但上述不工作對我來說
謝謝阿克巴爾。我根據你所說的改變了我的清單文件,但是現在我得到這個錯誤'ed從'https://maps.gstatic.com/intl/en_us/mapfiles/api-3/9/19/main加載腳本。 js',因爲Content-Security-Policy.'。任何想法爲什麼? – 2619
我更新了上述內容安全策略行以包含maps.gstatic.com行。我認爲你可能還需要添加更多的relxation政策。爲此,我建議您通過以下內容: http://developer.chrome.com/extensions/contentSecurityPolicy.html http://dvcs.w3。org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html –
感謝您的回答,您是否有任何解決方案將內容庫作爲內容腳本加載到頁面中?我在[這裏]添加了這個問題(https://stackoverflow.com/questions/48937438/refused-to-load-the-script-of-google-maps-library-inside-content-script-of-chrom) – Mohammad