chrome 扩展政策声明无效

chrome extension policy declaration not working

我在 chrome 扩展程序中加载外部 js 文件时遇到问题。这是我清单中的 csp 条目:

"content_security_policy": "script-src 'self' 'unsafe-eval' 'unsafe-inline' http://proto.office.atlassian.com; object-src 'self'" 

下面是我在 popup.html 中调用脚本的方式:

<script src="http://proto.office.atlassian.com/prototypes.js"></script>

这是我遇到的错误:

Refused to load the script 'http://proto.office.atlassian.com/prototypes.js' because it violates the following Content Security Policy directive: "script-src 'self'"

我已确认服务器正确设置了我的 CORS,我可以通过 XMLHttpRequest 提取脚本,但我似乎无法通过脚本标记加载一个脚本或评估它一次抓住它。任何帮助将不胜感激:)

清单中的 content security policy 必须明确允许外部脚本。

如果您需要一些外部 JavaScript 或对象资源,您可以通过将应该接受脚本的安全来源列入白名单来在一定程度上放宽政策...

允许通过 HTTPS 从 example.com 加载脚本资源的宽松政策定义可能如下所示:

"content_security_policy":"script-src 'self' https://example.com; object-src 'self'"

脚本只能通过 HTTPS 加载到扩展中,因此您必须通过 HTTPS 加载 jQuery CDN 资源:

<script src="https://ajax.googleapis.com/..."></script>
{
"manifest_version": 2,
"name": "One-click Kittens",
"description": "This extension demonstrates a 'browser action' with kittens.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'"
}