I'm building a chrome extension that has to click on a button on the webpage.
I can click the button from the console like this.
document.querySelector('#btn').click();
But, Where I try to do the same from content script, I get the following error.
Refused to run the JavaScript URL because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval'". 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.
The button element is selected correctly, but clicks doesn't work.
I also tried this one:
let clickEvent = new MouseEvent("click", {
bubbles: true,
cancelable: true,
clientX: 150,
clientY: 150,
});
document.querySelector('#btn').dispatchEvent(clickEvent);
But, got the same error. While this also works form console, but not from extension content_sript.
What is the possible solution for this? Thanks in advance.