Chrome extension: Uncaught Error: Code generation from strings disallowed for this context

烈酒焚心 提交于 2019-12-01 08:39:42

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

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));

Don't use internal script in popup.html. See Content Security Policy.

Try replacing all instances of "new Function" by "function(){}" it made my socket.io.js work.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!