简体   繁体   中英

Refused to evaluate a string as Javascript in chrome extension, in pdfjs

I am working on a chrome extension which uses PDFJS, but PDFJS latest release have some javascript which is returning JS as string

Function("return this")()

which is not allowed in chrome extension. so it giving following error

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'

So, how can i bundle pdfjs files in chrome extension to get rid of this issue?

Actually, the issue is within a lib used by PDFJS. Using the version 2.1.266 should fix the problem.

Here is a more detailed thread about the issue and other workarounds: https://github.com/mozilla/pdf.js/issues/11036

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM