Retrieve and Modify content of an XMLHttpRequest
Rather dirty but you can overwrite XMLHttpRequest.prototype.open
. Here is a Demo page. Since you're writing an extension, you must put this code in page context:
(function() {
// save reference to the native method
var oldOpen = XMLHttpRequest.prototype.open;
// overwrite open with our own function
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
// intercept readyState changes
this.addEventListener("readystatechange", function() {
// your code goes here...
console.log("Interception :) " + this.readyState);
}, false);
// finally call the original open method
oldOpen.call(this, method, url, async, user, pass);
};
})();
After this you can do anything I guess. Replace instance.readystatechange
, replace instance.addEventListener
, or listen to mutation events (although they are deprecated).