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
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.