'Any way to intercept and modify external static javascript in an HTML? tamper monkey or grease monkey or any other way

I have a page that loads javascript using a <script src="some/script.js"> tag. I wanted to replace a string in the external javascript file. And I found no way to do this in chrome. local overrides could work, but I don't want to keep the devtools open to make this work.

I tried the following

window.onbeforescriptexecute = function(e)=>(modifier code)

or

window.addEventListener("beforescriptexecute", (e)=>{modifier code});

But they don't work at all. I also tried this snippet here, still with no luck.

How can I make this work?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source