Chrome Extension - Content Security Policy - executing inline code

后端 未结 6 1663
梦谈多话
梦谈多话 2020-12-08 10:15

I am using an external JavaScript lib in my chrome extension. I has inline execution, so I get following kind of error

(The error I get on console)

6条回答
  •  情歌与酒
    2020-12-08 10:18

    You have something in your code like this:

    
    

    In a nutshell this is not allowed in chrome apps and extensions.

    Change this to the following and it will work:

    html:

    
    
    

    script.js:

    document.getElementById("myButton").addEventListener("click", myFunction); function myFunction(){ console.log('asd'); }

    Long story:

    In chrome apps, Content Security Policy does not allow inline javascript. So you have to put your javascript in a .js file and include it in your HTML.

    Further reading: https://developer.chrome.com/extensions/contentSecurityPolicy

提交回复
热议问题