I assuming the code you wrote is in the content script injected by PageMod. In that case, the XMLHttpRequest is subject to the Same Origin Policy of the host page, so it can't perform cross domain requests (at least in FF > 4). That's because you obtain that value.
The solution is doing the requests from the addon code, not the content script code, using the request module:
<https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/packages/addon-kit/docs/request.html>
In order to pass data between content script and addon code:
> Thanks a lot...
Hope it helps!
> Thanks a lot for the help!
> May you please be more detailed? Who is calling the Request? How to
> use the response?
Your code should be something like that (more or less):
// main.js
let pageMod = require("page-mod");
let data = require("self").data;
let Request = require("request").Request;
let myPageMod = pageMod.PageMod({
include: "*",
contentScriptFile: [data.url("panel.js")],
contentScriptWhen: "ready",
onAttach: function onAttach(worker) {
worker.on("message", function (url) {
Request({
url : "http://localhost:8080/Jelly/GetStuff",
contentType : "application/x-www-form-urlencoded",
content : "url=" + url,
onComplete : function onComplete(response) {
if (response.status === 200) {
worker.postMessage(response.text);
} else {
worker.postMessage(null);
}
}
}).post();
});
}
});
// panel.js
console.log("The Addon is working");
// Manage the response from the Addon code
onMessage = function onMessage(content) {
if (content === null) {
alert("Request failed")
} else {
console.log("data received: " + content);
}
}
// Send the URL to the Addon code
self.postMessage(document.URL);
You can find more information in the documentation:
<https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/packages/addon-kit/docs/page-mod.html>
<https://addons.mozilla.org/en-US/developers/docs/sdk/1.0/packages/addon-kit/docs/request.html>
Notice that, of course, you can send more meaningful data and complex
object from / to the addon code.
> Thanks again
You're welcome!