Last active
April 18, 2024 16:44
-
-
Save chappy84/a2c0b0d071b456e56fee856b2baae34b 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
const functionsToOverride = ['overrideMimeType', 'send']; | |
functionsToOverride.forEach(function(fnName) { | |
window.XMLHttpRequest.prototype[fnName] = new Proxy(window.XMLHttpRequest.prototype[fnName], { | |
apply: (target, thisArg, argumentsList) => { | |
console.log(fnName + ' arguments', argumentsList); | |
thisArg[fnName + 'Args'] = [...argumentsList]; | |
const retVal = target.apply(thisArg, argumentsList); | |
console.log(fnName + ' retVal', retVal); | |
return retVal; | |
} | |
}); | |
}); | |
window.XMLHttpRequest.prototype.open = new Proxy(window.XMLHttpRequest.prototype.open, { | |
apply: (target, thisArg, argumentsList) => { | |
console.log('open arguments', argumentsList); | |
thisArg.openArgs = [...argumentsList]; | |
const listenEvents = ['onreadystatechange', 'abort', 'error', 'load', 'loadstart', 'loadend', 'progress', 'timeout']; | |
listenEvents.forEach(function(eName) { | |
this.addEventListener(eName, function() { | |
console.log('event ' + eName + ' arguments', arguments); | |
}); | |
}, thisArg); | |
const retVal = target.apply(thisArg, argumentsList); | |
console.log('open retVal', retVal); | |
return retVal; | |
} | |
}); | |
window.XMLHttpRequest.prototype.setRequestHeader = new Proxy(window.XMLHttpRequest.prototype.setRequestHeader, { | |
apply: (target, thisArg, argumentsList) => { | |
console.log('setRequestHeader arguments', argumentsList); | |
if (!this.setRequestHeaderArgs) { | |
thisArg.setRequestHeaderArgs = new Array(); | |
} | |
thisArg.setRequestHeaderArgs.push([...argumentsList]); | |
var retVal = target.apply(thisArg, argumentsList); | |
console.log('setRequestHeader retVal', retVal); | |
return retVal; | |
} | |
}); | |
// Standard properties containing info about the request | |
// XMLHttpRequest.readyState | |
// XMLHttpRequest.response | |
// XMLHttpRequest.responseText | |
// XMLHttpRequest.responseType | |
// XMLHttpRequest.responseURL | |
// XMLHttpRequest.responseXML | |
// XMLHttpRequest.status | |
// XMLHttpRequest.statusText | |
// XMLHttpRequest.timeout | |
// XMLHttpRequest.withCredentials |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment