I'm building a firefox extension and would like to change the behavior of the XMLHTTPRequest object for every page loaded.
I found following code which should do the trick:
appcontent.addEventListener("load", function(event){
var original_xhr = XMLHttpRequest;
XMLHttpRequest = function () {
original_xhr();
alert ("I redefined this function");
}
alert ("Page loading");
} , true)
I have added this piece of code to my overlay.js file. The load event works correctly, since the "page loading" alert shows up. But the XMLHTTPRequest is not overwritten.
Does anyone know what's wrong?
I managed to get the information via another way. After intercepting the httpchannel I used following code to see if the request originated from an xhr request:
try
{
var callbacks = httpChannel.notificationCallbacks;
if (callbacks) {
var xhrInterface = callbacks.getInterface(Components.interfaces.nsIXMLHttpRequest);
// XHR REQUEST
}
}
catch (exc)
{
if (exc.name == "NS_NOINTERFACE") {
// NO XHR REQUEST
}
}