开发chrome插件报错:Refused to execute inline event handler because it violates the following Content Security Policy directive

Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem:". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution.

原因是 Chrome 插件不支持在插件的 html 上写内联 js, 如果需要添加事件,可以再外联 js 中写入:

错误的写法:

<div class="switch-box">
   <input class="switch-input" onchange="beautyUI()" type="checkbox" />
</div>

正确的写法

<div class="switch-box">
   <input class="switch-input" value="beautyUI" type="checkbox" />
</div>
$(function () {
  $('.switch-input').change(function () {
    var value = $(this).val()
    if (value === 'beautyUI') {
      beautyUI()
    }
  })
})
原文地址:https://www.cnblogs.com/unclefang/p/14168224.html