I'm in the process of developing a script that serves as a proxy/wrapper for the conventional XMLHttpRequest
object. This will allow me to intercept it, alter the responseText, and then return it back to the original onreadystatechange event.
The main objective is to stop the XMLHttpRequest
if the data the application is attempting to fetch is already stored locally, and instead feed the cached data into the app's success/failure callback functions. It's important to note that I have no control over the current AJAX callback methods used by the app.
Initially, I attempted the following approach:
var send = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function(data){
//Do some modifications here to change the responseText
send.call(this, data);
};
Unfortunately, it turns out that the responseText property is read-only.
Afterward, I took a step back and tried constructing my own complete native proxy to XMLHttpRequest
, essentially recreating my versions of the native functions. This concept was similar to what is discussed in this article...
However, things quickly became convoluted, and I continued to struggle with returning the modified data to the original onReadyStateChange
method.
Any recommendations or insights on how to achieve this? Is this goal even feasible?