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

前端 未结 1 1004
闹比i
闹比i 2020-12-03 00:57

I\'m developing a google chrome packaged app, when I put Sandbox in the manifest.json:

 {
  "manifest_version": 2,
  &         


        
1条回答
  •  眼角桃花
    2020-12-03 01:42

    Answer for your non sandbox related question:

    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

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