Webpack编译的Chrome扩展程序抛出`unsafe-eval`错误

亚历山大·米尔斯

使用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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Chrome扩展程序中的Wasm模块编译错误

$scope.$eval(stringFormula) 在 AngularJS 中抛出错误

Chrome扩展程序拒绝将字符串评估为JavaScript,因为emscripten生成的文件中的'unsafe-eval'

Chrome 扩展程序中的沙盒页面通过 iframe 传递消息时抛出错误

“ Chrome扩展程序抛出CRX文件错误” CRX_REQUIRD_PROOF_MISSING”

程序抛出编译时错误oracle

Google Chrome扩展程序错误

给定“ datetime.datetime.now()”的python ast.literal_eval抛出格式错误的字符串错误

测试Chrome扩展程序-要求错误

Chrome扩展程序保存表单错误

Chrome扩展程序错误,显示“ onCommand”

Chrome扩展程序错误加载jQuery

Chrome扩展程序注入脚本获取错误

Chrome扩展程序循环检查按钮错误

如果没有找到带有选择器的元素,Puppeteer page.$eval 会抛出错误

Chrome扩展程序更新-Chrome网上应用店系统错误

WebPack中的Typescript(加载程序)编译器错误

eval包含空白的bash错误

gdb eval "%s" 替换错误

更新后的PHP eval()错误

执行JavaScript时Eval()错误

Webpack 抛出意外的令牌错误

Chrome扩展程序“ Script-src”错误(自学)

Chrome扩展程序:如何全局捕获/处理内容脚本错误?

Chrome扩展程序在加载错误时重新加载页面

Chrome扩展程序“ MAX_WRITE_OPERATIONS_PER_MINUTE”错误

Chrome扩展程序:后台脚本捕获网络和HTTP错误

chrome扩展程序和保管箱dropin saver错误

Chrome扩展程序上传错误-缺少default_locale