Om3*_*3ga 10 javascript jquery google-maps google-chrome-extension content-security-policy
我正在制作谷歌浏览器扩展程序,我想使用谷歌地图.问题是,当我运行我的脚本然后它给了我这个错误
Refused to load script from 'https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXXXXXXX&sensor=false' because of Content-Security-Policy.
Run Code Online (Sandbox Code Playgroud)
这是我的清单文件
{
"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'"
Run Code Online (Sandbox Code Playgroud)
}
我正在添加这样的脚本
<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>
Run Code Online (Sandbox Code Playgroud)
为什么我一次又一次地收到这个错误?请帮忙...
更新一个
我将这两个权限添加到清单文件但仍无效
"https://maps.google.com/*",
"https://maps.googleapis.com/*",
Run Code Online (Sandbox Code Playgroud)
更新两个
我也使用了这种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"
Run Code Online (Sandbox Code Playgroud)
但上面对我来说也不起作用
Sye*_*bar 22
我认为这里的问题是您没有正确设置Google地图网址的内容安全政策.您应该将清单文件中的"content_security_policy"更改为以下内容:
"content_security_policy": "script-src 'self' https://maps.googleapis.com https://maps.gstatic.com; object-src 'self'"
Run Code Online (Sandbox Code Playgroud)
这只是意味着您允许从自我/当前页面以及"https://maps.googleapis.com"运行脚本.
试试这个,看看它是否有帮助.
归档时间: |
|
查看次数: |
17717 次 |
最近记录: |