Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Communication between page-mod and context-menu in Firefox Addon SDK

Via the context-menu module I detect over which DOM element the user clicked my custom context menu item "Mark":

var menu = require("context-menu").Item({
  label: "Mark",
  contentScriptFile: data.url("context.js"),
  onMessage: function (node) {
    //Send the node to page-mod
  }
});

context.js:

self.on("click", function (node, data) {
    self.postMessage(node);
});

Now I want to send this node reference to a page-mod module where every page having the pagemod's contentScript injected gets to know the node I clicked on (and mark the HTML element with a red border in every tab).

I know that sending the message to the pagemod via postMessage() is not possible, so how can I make these modules communicate? Is there an elegant worker solution?

like image 307
Patrick Green Avatar asked Nov 04 '22 12:11

Patrick Green


1 Answers

This isn't possible, the postMessage part is JSONifying your message, so the node in the message is ignored. You'll have you achieve your goal by sending data about the node to the addon context (using postMessage) instead.

like image 84
erikvold Avatar answered Nov 08 '22 06:11

erikvold