我目前正在编写一个支持 Manifest-v2 和 v3 的浏览器扩展,为了方便起见,它需要 CashJS 库(JQuery 的轻量级版本)。我希望我的内容脚本content/index.js
能够使用此库content/cash.min.js
,但我收到 CSP 违规声明:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-wThdlNeRf1Fp3UGuX3Ch9caqVJ8S7Wn41fdlaVxsRDE='), or a nonce ('nonce-...') is required to enable inline execution.
这是我的 manifest.json(适用于 v3):
...
"content_scripts": [{
...
"js": [
"content/cash.min.js",
"content/index.js"
]
}],
...
我尝试过content_security_policy
以各种方式使用(哈希和启用unsafe-inline
),但 Chrome 拒绝它:
"content_security_policy": "script-src 'self' 'sha256-wThdlNeRf1Fp3UGuX3Ch9caqVJ8S7Wn41fdlaVxsRDE='; object-src 'self';"
Invalid value for 'content_security_policy'.
尝试加载扩展时出现错误。我已阅读Mozilla 的此页面以及讨论此问题的其他帖子,但尚未找到适合我需要的解决方案。
Chrome 文档中的这篇文章提到了使用他们的sandboxing
功能,但它似乎只适用于网页,而不是脚本本身。
我真的不想截取此处建议的标头。
任何帮助将非常感激!