Patrick Green
Patrick Green

Reputation: 187

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?

Upvotes: 5

Views: 359

Answers (1)

erikvold
erikvold

Reputation: 16538

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.

Upvotes: 2

Related Questions