问题描述
我目前正在编写一个支持 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'.
。我已阅读 this page from Mozilla 以及其他讨论此问题的帖子,但尚未找到适合我需求的解决方案。
This article from Chrome's documentation 提到使用他们的 sandBoxing
功能,但它似乎只适用于网页,而不适用于脚本本身。
任何帮助将不胜感激!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)