Skip to content

Instantly share code, notes, and snippets.

@ruslangrimov
Last active August 29, 2019 11:48
Show Gist options
  • Save ruslangrimov/902843adb977cdad89fa04a929ac06b8 to your computer and use it in GitHub Desktop.
Save ruslangrimov/902843adb977cdad89fa04a929ac06b8 to your computer and use it in GitHub Desktop.
Intercept any ajax request
(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