I am trying to use micro template engine in chrome extension and getting the following error : Uncaught Error: Code generation from strings disallowed for this context
You're using the tmpl function incorrect, try this:
var s = tmpl('userlisttemplate', { items: data });
Also in your template you're expecting items to be an array, but the json returned is an object (unless manifest.json
is not the actual requested json, in which case I'll need the returned data)
manifest.json also does not include any UserName
mentioned in the template
trying the following I do get results:
var s = tmpl('userlisttemplate',{
items: [{
"UserName": "test1"
},{
"UserName": "test2"
},{
"UserName": "test3"
}]
});
$('body').append($(s));
Try replacing all instances of "new Function"
by "function(){}"
it made my socket.io.js work.
This templating library can't be used in a regular extension page because it uses new Function()
with a string, which is now disallowed under Chrome's new Content Security Policy for extensions created with manifest version 2. see here
Don't use internal script in popup.html. See Content Security Policy.