【问题标题】:Refused to evaluate a string as Javascript in chrome extension, in pdfjs拒绝在 pdfjs 中将字符串评估为 chrome 扩展中的 Javascript
【发布时间】:2019-06-22 17:14:36
【问题描述】:

我正在开发一个使用 PDFJS 的 chrome 扩展,但 PDFJS 最新版本有一些 javascript 将 JS 作为字符串返回

Function("return this")()

这在 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'

那么,我如何将 pdfjs 文件捆绑到 chrome 扩展中来解决这个问题?

【问题讨论】:

  • 我猜你必须修改默认的 CSP。见this answer
  • 感谢 @wOxxOm 帮助!

标签: javascript webpack google-chrome-extension pdfjs


【解决方案1】:

通过向 manifest.json 中的 content_security_policy 添加“unsafe-eval”选项解决了该问题。

【讨论】:

  • 这不太正确。这是一个非常危险的添加权限,并且在不解决根本问题的情况下会使 google 的批准需要更长的时间。固定 PDFjs 版本是一个更好的答案 IMO
【解决方案2】:

实际上,问题出在 PDFJS 使用的库中。使用 2.1.266 版本应该可以解决问题。

这里是关于该问题和其他解决方法的更详细的帖子:https://github.com/mozilla/pdf.js/issues/11036

【讨论】:

    猜你喜欢
    • 2014-09-08
    • 1970-01-01
    • 2018-01-15
    • 2022-11-23
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多