我正在尝试创建一个 Chrome 扩展,但我的 JS 都不起作用。控制台显示此错误:
Refused to load the script 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js' because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem: chrome-extension-resource:".
为什么它会阻止我的 jQuery 运行?
最佳答案
正如在 Chome 上解释的那样 website , 有一个内容安全策略阻止您的脚本加载远程脚本:
A relaxed policy definition which allows script resources to be loaded from example.com over HTTPS might look like:
"content_security_policy": "script-src 'self' https://example.com; object-src 'self'"
所以在你的情况下,manifest.json
应该包含:
{
"name": "My Extension",
"manifest_version": 2,
"background":{
"scripts": [...]
},
"content_security_policy": "script-src 'self' https://example.com; object-src 'self'",
}
关于javascript - Chrome 扩展 "Refused to load the script because it violates the following Content Security Policy directive",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34950009/