DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Intercepting XMLHttpRequest requests
Adam K Dean
Adam K Dean

Posted on

Intercepting XMLHttpRequest requests

Let's kick off the continuation of my code blogging with a very helpful little snippet. I'm just removing this from a codebase so it can sit here for eternity instead.

(function(open) {
    XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
        // do some magic
        open.call(this, method, url, async, user, pass);
    };
})(XMLHttpRequest.prototype.open);
Enter fullscreen mode Exit fullscreen mode

This will intercept the request before it happens, and once you've done whatever changes you need to do, be it logging or tagging, you can continue it.

Top comments (0)

Hacktoberfest is happening now!


It is a month-long celebration of open source. For a lot of devs, its their introduction to open source.



Check out the Hacktoberfest tag on DEV to keep up with the latest!