My userscript's task is fairly simple -to listen to XHR requests via an XHR bridge sort of functionality, manipulate the data received, and return it back. Everything happening transparently, of course.
I came across this reply How can I intercept XMLHttpRequests from a Greasemonkey script? on SO -- which provides the following code-snippet:
(function(open) {
XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
this.addEventListener("readystatechange", function() {
console.log(this.readyState);
}, false);
open.call(this, method, url, async, user, pass);
};
})(XMLHttpRequest.prototype.open);
The code works as expected when pushed via FireBug. It, however, doesn't do anything in a Greasemonkey script.
On further searches, I came across another reply: how intercept xhr with greasemonkey -- which mentions that:
Greasmonkey and Firefox 3.x doesn't currently support the "prototype"-property. Please see the following ticket for more information: http://greasemonkey.devjavu.com/ticket/164
I have two basic queries:
- Does this apply to Fx v3.5.x as well? (Note: The ticket link on devjavu.com isn't accessible)
- What does signature
(function(){})()
mean in Javascript. (Kindly bear, am not an expert in advanced JS).