Error prompted by dynamic binding JS event on Chrome extension page

  • 2020-03-30 01:40:59
  • OfStack

Problem description:

When developing the Chrome extension, js is needed in the popup.html of the page. When writing js directly in the dynamic binding js event, it will prompt:

Refused to execute the inline script because it violates the following Content Security Policy directive: "script - SRC 'self' chrome - the extension - the resource:"..

Solutions:

References external js files to dynamically bind js events in popup.html, for example:
 
<script type="text/javascript" charset="utf-8" src='test.js'></script> 

Test. In js:
 
var listbox = document.getElementById("showlist"); 
listbox.onclick=function(){ 
document.getElementById("player_sidebar").style.width = 100; 
} 

Related articles: