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

前端 未结 4 861
离开以前
离开以前 2021-01-14 09:33

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

相关标签:
4条回答
  • 2021-01-14 09:52

    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));
    
    0 讨论(0)
  • 2021-01-14 10:06

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

    0 讨论(0)
  • 2021-01-14 10:07

    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

    0 讨论(0)
  • 2021-01-14 10:14

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

    0 讨论(0)
提交回复
热议问题