Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 内容安全策略:在新(弹出)窗口中加载谷歌地图_Javascript_Google Maps_Google Chrome Extension_Content Security Policy - Fatal编程技术网

Javascript 内容安全策略:在新(弹出)窗口中加载谷歌地图

Javascript 内容安全策略:在新(弹出)窗口中加载谷歌地图,javascript,google-maps,google-chrome-extension,content-security-policy,Javascript,Google Maps,Google Chrome Extension,Content Security Policy,在my chrome extension中,当用户单击浏览器操作符号时,将打开一个新的(弹出)窗口加载Google地图。要打开窗口,我使用以下代码段 chrome.browserAction.onClicked.addListener(function() { chrome.windows.create({'url': 'popup.html', 'width': 500, 'height': 400 }); }); popup.html如下所示: <!doctype html>

在my chrome extension中,当用户单击浏览器操作符号时,将打开一个新的(弹出)窗口加载Google地图。要打开窗口,我使用以下代码段

chrome.browserAction.onClicked.addListener(function() {
  chrome.windows.create({'url': 'popup.html', 'width': 500, 'height': 400 });
});
popup.html
如下所示:

<!doctype html>
<html>
  <head>
    <title>Popup</title>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>
    <script src="popup.js"></script>
  </head>
  <body>
    <div id="map-canvas" style="width:100%; height:100%"></div>
  </body>
</html>

现在我想知道,这是否是正确的方法。我如何知道所需的https URL列表不会随时间而改变?我尝试了通配符(
https://*/*
),但这完全失败了。或者我完全使用wring方法。

无法保证Google Maps将从哪些域加载脚本。如果您需要使用更宽松的CSP规则,则如下所示:

script-src 'self' 'unsafe-eval' https:;

https:
表示可以从任何域加载,但必须通过SSL。这不是一个理想的CSP规则集,因为它更容易受到JavaScript安全问题的影响。

Abraham,谢谢!我必须将其更改为
https://
,否则我会得到一个错误,与我的
https://*/*
方法一样。我知道这不是一个好的解决方案,但我只需要它来实现概念验证…至少目前是这样。很好,你让它工作了。奇怪的是,它使用了
https:
作为示例。@Christian注意到
https://
是受支持的。您不能在Chrome扩展的内容安全策略中使用过于通用的通配符(请注意,
https://
从来都不是有效的CSP指令,这一点也已得到修复)。请将其放在这里,以防它对任何人都有帮助。这对我有用。“内容安全策略”:“连接src;脚本src'self”“不安全评估”“;对象src'self”“,
script-src 'self' 'unsafe-eval' https:;