I am writing a userscript that is injected into a webpage. The script reads some data from a web-server and I want to send messages to a listening application to react to the data.
For now, all I'm doing is trying to send a string command to my listening application and see if I can read it. My code worked before it was injected, but afterwards I get an "undefined reference error".
I suspect that this has something to do with this "Greasemonkey access violation". However, I have been unable to find a solution that works. I'm developing in Chrome.
Here is the section of code I can't get to work.
GM_xmlhttpRequest({
method: "POST",
url: "http://localhost:7777",
data: "testing123",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
onload: function(response)
{
if (response.responseText.indexOf("TEST") > -1)
{
console.log("Response confirmed...");
}
}
});
I'm pretty new to scripting so maybe I'm missing something obvious. How do I get this to work in injected code?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…