I suspect that I am missing something, but I have looked high and low for solutions or alternatives with no luck...
I have a Greasemonkey script (I don't want to copy-paste the whole thing here) that won't run when I add the line // @grant GM_xmlhttpRequest
. As a test I added the same line to IITC (one of the few greasemonkey scripts I have on my system) and it also failed to load. Fails with Greasemonkey 2.3 & 3.0, Running Firefox 36.0.1. I receive no error messages in the browser console.
My script adds a listener (this.addEventListener("readystatechange", function() {
) when XMLHttpRequest open function is called ((function(open) {
, XMLHttpRequest.prototype.open = function(method, url, async, user, pass) {
) and "intercepts" the received data and sends it to my own server on a local network to be logged. The script does appear to run through the code in the .js file, but the listener never executes. The only thing I can think of is that the code in the script executes as expected, but when running from a listener it runs outside of the context of the .js file, but in that case I would expect to see a function not defined error.
This is how I am forming my request:
GM_xmlhttpRequest({
method: "POST",
url: "http://10.0.0.149/cgi-bin/test.py",
data: "logdata=logthis",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
});
When the @grant
line is taken out the script otherwise functions correctly (and logs to console properly), except that I get a function not defined error (as expected).
console.log("LogData: " + this.responseText);
Essentially I want a line of code to replace that one where I can send the responseText
to a logging server on my home network (I have also considered using a proxy to do the job!).