问题
I'm developing a chrome extension using Kango framework, and I waned to use both Google Analytics and facebook SDK. I edited the manifest file to include the follwoign
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com https://connect.facebook.net; object-src 'self'; default-src 'self' 'unsafe-eval' chrome-extension-resource: https://*.facebook.net https://*.facebook.com; style-src 'self' 'unsafe-inline' chrome-extension-resource: https://*.facebook.net https://*.facebook.com; frame-src 'self' 'unsafe-inline' chrome-extension-resource: https://*.facebook.net https://*.facebook.com"
But it doesn't work! and I'm getting the following error
Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' https://ssl.google-analytics.com https://connect.facebook.net".
回答1:
Change the script-src
directive to have 'unsafe-eval'
at the end.
script-src 'self' https://ssl.google-analytics.com https://connect.facebook.net 'unsafe-eval';
Note that this will lower the security of your extension as random strings of JavaScript can be executed.
来源:https://stackoverflow.com/questions/20645651/how-to-load-google-analytics-and-facebook-sdk-in-chrome-extension