Underscore.js _.template causes error from Chrome extension

后端 未结 6 658
北荒
北荒 2020-12-16 12:52

If I use underscore.js\'s _.template() from inside a Google Chrome extension I get the following error in the console:

Uncaught Error: Code generation

6条回答
  •  旧时难觅i
    2020-12-16 13:56

    Many thanks to the Chromium list contributor who pointed out that to create a Function object in the way underscore is doing it requires the manifest.json option for content_security_policy to include 'unsafe-eval'.

    As an example, your manifest.json could be

    {
      "manifest_version": 2,
      ...
      "content_security_policy": "script-src 'self' 'unsafe-eval'",
      ...
    }
    

    and then the underscore behavior would work because this policy allows it. For more information on the format see the Chrome documentation on this option here.

提交回复
热议问题