CHROME扩展笔记之拒绝unsafe-eval求值
开发插件选项页时由于引用了vue框架开发前端页面,导致拒绝eval求值问题Uncaught EvalError: Refused to evaluate a string as JavaScript because ‘unsafe-eval’ is not an allowed source of script in the following Content Security Policy di
开发插件选项页时由于引用了vue框架开发前端页面,导致拒绝eval求值问题
Uncaught EvalError: 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’ blob: filesystem:”.
这是浏览器自带的"网页安全政策"(Content Security Policy)导致的;浏览器默认的Content-Security-Policy的安全政策时“ default-src ‘self’ ”。我们可以通过manifest.json重新配置Content Security Policy的配置开启eval功能;
// 代码如下,可直接复制
,"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
注意:修改插件配置文件manifest.json需要重新安装插件才能生效(先卸载再重新导入)
关于MV3
根据谷歌插件开发文档描述MV3 不允许对extension_pages的CSP 修改进行修改。如script-src, object-src(而在MV2中这些是允许修改的)
更多推荐
所有评论(0)