Last active
June 23, 2023 09:58
-
-
Save wyvernzora/b6a73444a597011b7dec to your computer and use it in GitHub Desktop.
Browser XHR Spy
This file contains 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
/** | |
* The following code, when executed in a browser's JS console, | |
* will log detailed information about every XHR made from the | |
* web page. Perfect for spying on API calls. | |
*/ | |
(function() { | |
var XHR = XMLHttpRequest.prototype; | |
// Remember references to original methods | |
var open = XHR.open; | |
var send = XHR.send; | |
// Overwrite native methods | |
// Collect data: | |
XHR.open = function(method, url) { | |
this._method = method; | |
this._url = url; | |
return open.apply(this, arguments); | |
}; | |
// Implement "ajaxSuccess" functionality | |
XHR.send = function(postData) { | |
this.addEventListener('load', function() { | |
this._body = postData; | |
console.log(this); | |
}); | |
return send.apply(this, arguments); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment