How would I block a URL from loading like AdBlock does?
For example https://example.com/hi.js
I've tried this with XMLHttpRequest
, but didn't succeed.
I would very like to do this in JavaScript. Not DevTools or some other stuff.
XMLHttpRequest.prototype.realOpen = XMLHttpRequest.prototype.open;
// Create a new function to filter out certain urls
var myOpen = function(method, url, async, user, password) {
// Redirects the /pause to /play
// (which will do nothing since Spotify is already playing)
if (url.match(/doubleclick/gi)) {
alert("a")
url = "about:blank";
}
this.realOpen(method, url, async, user, password);
}
// Overwrite the original open with our modded version
XMLHttpRequest.prototype.open = myOpen;
Please DO NOT answer with "it's not possible" or "use DevTools instead" when clearly AdBlock is capable of it.
AdBlock is a browser extension that uses WebExtensions API
See this article for more info on how to do what you want