I am trying to create a Chrome extension that shows a simple map. I tried loading the Google Maps API using the attached code inside the content script :
content script
var g = document.createElement('script'); g.src = "https://maps.googleapis.com/maps/api/js?key=MY_KEY&libraries=places"; (document.head || document.documentElement).appendChild(g);
And of course, I changed the content_security_policy as follows: "content_security_policy": "script-src 'self' https://maps.googleapis.com https://maps.gstatic.com https://ssl.google-analytics.com https://www.google.com; object-src 'self'"
content_security_policy
"content_security_policy": "script-src 'self' https://maps.googleapis.com https://maps.gstatic.com https://ssl.google-analytics.com https://www.google.com; object-src 'self'"
But I still could not get it to work, I still get an error message inside the Chrome console:
Refused to download script ' https://maps.googleapis.com/maps-api-v3/api/js/32/2/common.js ' because it violates the following content security policy directive: "script -src https: / /clients4.google.com/insights/consumersurveys/ https://www.google.com/js/bg/ 'self' 'insecure-built-in' 'insecure-eval' https://mail.google.com/_/ scs / mail-static / https://hangouts.google.com/ https://talkgadget.google.com/ https: //*.talkgadget.google.com/ https://www.googleapis.com/appsmarket/ v2 / installedApps / https://www-gm-opensocial.googleusercontent.com/gadgets/js/ https://docs.google.com/static/doclist/client/js/ https://www.google.com/ tools / feedback / https://s.ytimg.com/yts/jsbin/ https://www.youtube.com/iframe_api https://ssl.google-analytics.com/ https://apis.google.com // scs / abc-static / https://apis.google.com/js/ https://clients1.google.com/complete/ https://apis.goog le.com//scs/apps-static/_/js/ https://ssl.gstatic.com/inputtools/js/ https://ssl.gstatic.com/cloudsearch/static/o/js/ https: / /www.gstatic.com/feedback/js/ https://www.gstatic.com/common_sharing/static/client/js/ https://www.gstatic.com/og/_/js/ ".
I saw a lot of questions here, but nothing works for me! A very clear answer was this , but it loads the library in a popup window inside the extension. My scenario is to load maps into the content script. Does this mean that the problem with the content policy area is not related to the extension, but to the site itself?
I tried to enter the code using chrome.tabs.executeScript , but I got some errors from the console:
chrome.tabs.executeScript
maps.googleapis.com/maps-api-v3/api/js/32/2/stats.js:1 Uncaught TypeError: Cannot read property '__gjsload__' of undefined at maps.googleapis.com/maps-api-v3/api/js/32/2/stats.js:1 (anonymous) @ maps.googleapis.com/maps-api-v3/api/js/32/2/stats.js:1 maps.googleapis.com/maps-api-v3/api/js/32/2/common.js:1 Uncaught TypeError: Cannot read property '__gjsload__' of undefined at maps.googleapis.com/maps-api-v3/api/js/32/2/common.js:1 (anonymous) @ maps.googleapis.com/maps-api-v3/api/js/32/2/common.js:1 maps.googleapis.com/maps-api-v3/api/js/32/2/util.js:1 Uncaught TypeError: Cannot read property '__gjsload__' of undefined at maps.googleapis.com/maps-api-v3/api/js/32/2/util.js:1
No one has answered this question yet.
See similar questions:
or similar: