Domanda

I have two tabs that my extension uses and I wanted to pass events back and forth between them. I've already developed a Google Chrome extension that does this via the background page api, but there doesn't seem to be an equivalent in firefox.

I thought message-manager in the firefox extension docs would do the trick, but the documentation on the object is quite poor.

I'd be just as happy with using one of the tabs to control the other if I can't directly import the ideas of a background page from google chrome api.

Any help/guidance would be great.

È stato utile?

Soluzione

To do this, you need to set up an event pipe in main.js that accepts events from one page's content script and pipes it to the other page's content script:

https://addons.mozilla.org/en-US/developers/docs/sdk/1.7/dev-guide/guides/content-scripts/index.html

I'm not completely sure what your use case is so it's hard to recommend more specific techniques. What you would do is:

  • ensure that a content script is attached to each tab
  • when a given event that happens in a tab, emit that event to main.js using self.port.emit
  • when that event reaches main.js, emit it to the worker for the other tab.

One thing that isn't clear to me is whether these 2 tabs will be the only tabs open with that specific url?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top