Angularjs 如何使用Angular在Chrome扩展中加载GoogleMaps脚本?
我正在使用AngularJS构建一个Chrome扩展,它使用Google地图(特别是位置) 我正在寻找类似的功能Angularjs 如何使用Angular在Chrome扩展中加载GoogleMaps脚本?,angularjs,google-maps,google-chrome-extension,Angularjs,Google Maps,Google Chrome Extension,我正在使用AngularJS构建一个Chrome扩展,它使用Google地图(特别是位置) 我正在寻找类似的功能 <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <style type="text/css"> body { font-family: Arial;
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
body
{
font-family: Arial;
font-size: 10pt;
}
</style>
</head>
<body>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places"></script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('txtPlaces'));
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var address = place.formatted_address;
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var mesg = "Address: " + address;
mesg += "\nLatitude: " + latitude;
mesg += "\nLongitude: " + longitude;
alert(mesg);
});
});
</script>
<span>Location:</span>
<input type="text" id="txtPlaces" style="width: 250px" placeholder="Enter a location" />
</body>
</html>
我听到一个错误说
Refused to load the script 'http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places' because it violates the following Content Security Policy directive: "script-src 'self' https://ssl.google-analytics.com".
当我将清单更改为
"content_security_policy": "script-src 'self' https://maps.googleapis.com https://ssl.google-analytics.com; object-src 'self'",
我仍然收到相同的“拒绝加载脚本”错误
所以我的问题是:如何在不直接加载HTML文件的情况下加载Google地图库?,内联脚本不会执行,只加载本地脚本
除了在
content\u securiy\u policy
字段中添加远程url(以https
开头),您还应该将内联脚本提取到外部文件,然后将其包括在内。我能够将其添加到清单中。它以前不工作,因为我没有将文件重新加载到chrome。现在,我重新加载,这是工作 试试https://maps.googleapis.com/maps/api/js?sensor=false&libraries=places
我使用https仍然会遇到同样的错误
"content_security_policy": "script-src 'self' https://maps.googleapis.com https://ssl.google-analytics.com; object-src 'self'",