Edit Javascript of a website before the page is loaded Chrome Extension

Viewed 304

I am trying to make a chrome extension that can edit and remove parts of Javascript of a webpage preferably before the page is loaded.

For Example, the following script tag is within my test html website.

<script>
document.addEventListener("visibilitychange", onchange);
function onchange(){
    console.log('left');
}
</script>

This code tells the console when the user switches tabs. I would like to be able to edit this specific code only to prevent this from happening. Can I modify the text of JavaScript before runtime?

1 Answers

You cant modify the code before runtime but you can remove the event listener.

removeEventListener("visibilitychange", onchange);

Note: You technically can edit JS before it's executed in Chrome using LocalOverrides however it requires you to have your devtools open on page load.

Related