Last active
November 27, 2019 22:49
-
-
Save jefersondaniel/b8de1dbe5fa48ef710b63f2283fb4344 to your computer and use it in GitHub Desktop.
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(XHR) { | |
"use strict"; | |
var open = XHR.prototype.open; | |
var send = XHR.prototype.send; | |
var openUrl = null; | |
var responses = []; | |
XHR.prototype.open = function(method, url) { | |
openUrl = url; | |
open.apply(this, arguments); | |
}; | |
XHR.prototype.send = function(data) { | |
var self = this; | |
var oldOnReadyStateChange; | |
var url = openUrl; | |
function onReadyStateChange() { | |
if(self.status === 200 && self.readyState == 4 /* complete */) { | |
if (/URL_REGEX/.test(url)) { | |
console.log(url); | |
responses.push({ | |
url: url, | |
data: self.responseText, | |
}); | |
} | |
} | |
if(oldOnReadyStateChange) { | |
oldOnReadyStateChange(); | |
} | |
} | |
if(this.addEventListener) { | |
this.addEventListener("readystatechange", onReadyStateChange, | |
false); | |
} else { | |
oldOnReadyStateChange = this.onreadystatechange; | |
this.onreadystatechange = onReadyStateChange; | |
} | |
send.apply(this, arguments); | |
} | |
window.__RESPONSES = responses; | |
})(XMLHttpRequest); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment