I have implemented a method to intercept AJAX requests on my website by modifying the XMLHttpRequest.prototype
open
and send
methods. This approach has been successful in all browsers I tested, except for Chrome on iOS (iPhone) where it seems to continuously execute the code I altered in the prototype, eventually causing the page to crash.
Here is a basic example of the code snippet I am using:
var open = XMLHttpRequest.prototype.open; // Storing the original function
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
alert('open'); // My custom code here
open.call(this, method, url, async, user, pass); // Calling the original function
};
You can view a simple demonstration of this behavior on JSBin with Chrome on iOS: Demo
Based on this answer, the code I am using is considered safe and should not cause any issues. Strangely, Chrome for iOS is the only browser exhibiting this unexpected behavior.
This issue has been perplexing me for the past two days, so any suggestions or workarounds would be greatly appreciated.