Refused to execute inline event handler because it violates CSP. (SANDBOX)

回眸只為那壹抹淺笑 提交于 2019-11-29 03:38:25
kailniris

Answer for your non sandbox related question:

You have something in your code like this:

<button onclick="myFunction()">Click me</button>

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

Change this to the following and it will work:

  • html:

    <button id="myButton">Click me</button>
    <script src="script.js"></script>
    
  • 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

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