![](https://stackoverflow.max-everyday.com/wp-content/uploads/2024/05/Screenshot-2024-05-11-at-9.51.07 AM.png?v=1715392606)
在chrome extension 動態產生內容時,發生錯誤訊息:
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-...'), or a nonce ('nonce-...') is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the 'unsafe-hashes' keyword is present.
Note that inline event handlers are blocked as well:
HTMLCopy to Clipboard
<button id="btn" onclick="doSomething()"></button>
You should replace them with addEventListener
calls:
JSCopy to Clipboard
document.getElementById("btn").addEventListener("click", doSomething);