Skip to content

Instantly share code, notes, and snippets.

@likwrk
Forked from indiejoseph/gist:3047593
Created December 20, 2015 08:59
UserScript - XHR Interceptor
function Interceptor(nativeOpenWrapper, nativeSendWrapper) {
XMLHttpRequest.prototype.open = function () {
// Code here to intercept XHR
return nativeOpenWrapper.apply(this, arguments);
}
XMLHttpRequest.prototype.send = function () {
this.onloadend = function() {
if(this.capture) {
console.log(this.responseText);
}
}
return nativeSendWrapper.apply(this, arguments);
}
}
// Injects the code via a dynamic script tag
var script = document.createElement("script");
script.type = "text/javascript";
script.textContent = "(" + Interceptor + ")(XMLHttpRequest.prototype.open, XMLHttpRequest.prototype.send);";
document.documentElement.appendChild(script);
document.documentElement.removeChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment