-
-
Save likwrk/427eb065b8219f39bed6 to your computer and use it in GitHub Desktop.
UserScript - XHR Interceptor
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 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