I am building a Chrome extension and I'm facing some troubles while trying to overwrite some JavaScript events on the page the extension is going to run on.
I've built a mockup page with HTML that looks like so:
document.querySelector('#f').onclick = function() {
document.body.innerHTML += 'you clicked';
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<button id='f'>click me</button>
</body>
</html>
The extension is supposed to change the onclick event. So here we have the content script:
document.querySelector('#f').onclick = function() {
document.body.innerHTML += 'it is the extension';
}
But instead both of the functions are executed independently from each other - The innerHTML
added when you click on the button is you clickedit is the extension
. Why are both functions executed and how can i solve this issue?
Thanks in advance.