In a Chrome extension, click events on both the extension icon and a button within the popup page are not generating the expected response of incrementing a JavaScript variable.
To debug the issue, inspect the popup page and examine the console logs. The error message likely indicates a Content Security Policy (CSP) violation:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:".
Inline scripts within the HTML page violate the default CSP. Inline JavaScript is not permitted under this policy.
To resolve the issue, eliminate all inline JavaScript from the HTML file and place it in a separate JavaScript file.
hello.html (Popup Page)
popup.js
var a = 0; function count() { a ; document.getElementById('demo').textContent = a; } document.getElementById('do-count').onclick = count;
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3