Skip to content

Instantly share code, notes, and snippets.

@plmrry
Created October 27, 2016 19:30
Show Gist options
  • Save plmrry/ac0af595d41bdb3391d1e45f895fcbb6 to your computer and use it in GitHub Desktop.
Save plmrry/ac0af595d41bdb3391d1e45f895fcbb6 to your computer and use it in GitHub Desktop.
Capture XHR Requests
(function() {
var XHR = XMLHttpRequest.prototype;
var open = XHR.open;
var send = XHR.send;
XHR.open = function(method, url) {
requests.push(this);
this._method = method;
this._url = url;
return open.apply(this, arguments);
};
XHR.send = function(data) {
// this.addEventListener('load', function() {
// /* Method */ this._method
// /* URL */ this._url
// /* Response body */ this.responseText
// });
const that = this;
if (blocked.some(function(regex) { return that._url.match(regex) })) return;
return send.apply(this, arguments);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment