I am trying to develop an addon for Firefox (using the latest version of JetPack) that sends some AJAX data on the click on a context item. However, unfortunately it seems I have hit some problem.
Please see the code below – I have tried to make it as simple as possible to understand.
// file main.js
var contextMenu = require("context-menu");
var data = require("self").data;
exports.main = function(options, callbacks) {
var contextMenuItemContentScriptFiles = [data.url("content.js")];
var menuItemSelection = contextMenu.Item({
label: "This is a test",
contentScriptFile: contextMenuItemContentScriptFiles,
context: contextMenu.SelectionContext(),
onMessage: function (testVar) {
alert(testVar);
}
});
};
// file content.js
self.on("click", function (node, data) {
alert("before posting");
self.postMessage("messagePosted");
alert("after posting");
});
The code alerts “before posting” and “after posting” but it doesn’t alert “messagePosted” as I was expecting.
Can you please help me at finding the problem?
Found the problem.
I had to use console.log, not alert from the main script.