使用Webpack编译后重新加载Chrome扩展程序时出现此错误:
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: chrome-extension-resource:".
at new Function (<anonymous>)
at evalExpression (compiler.js:33919)
at jitStatements (compiler.js:33937)
at JitCompiler.webpackJsonp.../../../compiler/esm5/compiler.js.JitCompiler._interpretOrJit (compiler.js:34520)
at JitCompiler.webpackJsonp.../../../compiler/esm5/compiler.js.JitCompiler._compileTemplate (compiler.js:34448)
at compiler.js:34347
at Set.forEach (<anonymous>)
at JitCompiler.webpackJsonp.../../../compiler/esm5/compiler.js.JitCompiler._compileComponents (compiler.js:34347)
at compiler.js:34217
at Object.then (compiler.js:474)
我的CSP授予unsafe-eval
权限。
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
如何允许eval()
在我的代码中使用(因为Webpack使用它来生成源映射)?
Chrome扩展程序是不允许使用unsafe-eval
,或eval
在所有的事实。
https://developer.mozilla.org/zh-CN/Add-ons/WebExtensions/Content_Security_Policy
制作Chrome扩展程序时,请了解它受到内容安全政策的严格限制。确保阅读并理解WebExtensions内容安全策略。如果您想要一个内联脚本,例如:
<script>
alert('hello')
</script>
您将必须将脚本标签的内容计算为其SHA256值,并将其添加到清单中,以便允许其执行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句