Last active
August 29, 2019 11:48
-
-
Save ruslangrimov/902843adb977cdad89fa04a929ac06b8 to your computer and use it in GitHub Desktop.
Intercept any ajax request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(open) { | |
XMLHttpRequest.prototype.open = function(method, URL, async, user, password) { | |
if (URL.indexOf("xxxx") > -1) { | |
// console.log(method, URL, async, user, password); | |
this.addEventListener('readystatechange', function () { | |
if(this.responseText !== '' && this.readyState == 4) { | |
var oldResponseText = this.responseText; | |
// ... | |
var newResponseText = 'blabla'; | |
Object.defineProperty(this, 'responseText', { | |
get: function() { return newResponseText; }, | |
}); | |
} | |
}, false); | |
} | |
open.call(this, method, URL, async, user, password); | |
}; | |
})(XMLHttpRequest.prototype.open); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment