Check out this neat trick for monitoring XMLHttpRequest object activity by intercepting open() calls:
(function(){
var ajaxOpen=window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open=function(m,u,a){
this.addEventListener("load", function(){ console.log("ajax loaded", new Date(), m, u, a ); });
return ajaxOpen.call(this,m,u,a);
};
}());
$.get("/", function(e){
console.log(e.length+" bytes fetched");
});
When used on a page, you'll see logs similar to the example below:
ajax loaded Fri May 30 2014 09:56:34 GMT-0500 (Central Daylight Time) POST /posts/23957352/edit-submit/b4dd7272-6618-4c79-9810-e8ff71122b51 true
It's worth noting that jQuery is only used here to demonstrate the broad impact on all ajax calls without altering any specific libraries or code. With some tweaks, this method can be expanded to capture additional information like data, response size, and call duration.
While there may be a slight increase in memory usage and potential compatibility issues with older browsers due to manipulation of "host objects," this approach can be valuable for debugging, testing, and performance evaluation purposes.
EDIT: I also discovered that modern browsers now support multiple event handlers using addEventListener(), allowing for logging of actual responses in the updated code above.