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


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 中写入:

错误的写法:

正确的写法

$(function () {
  $('.switch-input').change(function () {
    var value = $(this).val()
    if (value === 'beautyUI') {
      beautyUI()
    }
  })
})