I'm writing a Greasemonkey script where I want to overload the XMLHttpRequest.prototype.open
function to hijack the Ajax calls on the page.
I'm using the following code:
// ==UserScript==
// @name name
// @namespace namespace
// @description desc
// @include https://url*
// @version 1.0
// ==/UserScript==
if (XMLHttpRequest.prototype) {
//New Firefox Versions
XMLHttpRequest.prototype.realOpen = XMLHttpRequest.prototype.open;
var myOpen = function(method, url, async, user, password) {
//call original
this.realOpen (method, url, async, user, password);
myCode();
}
//ensure all XMLHttpRequests use our custom open method
XMLHttpRequest.prototype.open = myOpen ;
}
This works well until I start using GM APIs. When I just add the following line to the meta section my code breaks, and myOpen
is no longer called:
// @grant GM_getValue
This could be any GM API really, and my code breaks.
Everything else in my script works fine even with the GM APIs, it's just the overload of the XMLHttpRequest.prototype.open
function that breaks.
I can kind of workaround it by using waitForKeyElements
, however, I don't like it because it slows down the browser due to the interval it uses.
Any ideas why the GM APIs break the overload of the XMLHttpRequest.prototype.open
call?
Many thanks,
Peter