This is somewhat more complicated with the Add-on SDK, because you don’t communicate with tabs there - you communicate with the employees you create. And the system will not track workers, you have to do it yourself. Something like this should work (unverified code):
var workers = [];
var pageMod = require("page-mod");
pageMod.PageMod({
include: ...,
contentScriptFile: ...,
onAttach: function(worker)
{
workers.push(worker);
worker.on("detach", function()
{
var index = workers.indexOf(worker);
if (index >= 0)
workers.splice(index, 1);
});
}
});
This ensures that the variable workerscontains a list of active workers ( Workerobject documentation ). Therefore, when you need to send a message to an employee assigned to a specific tab, do the following:
var tabs = require('tabs');
for (var i = 0; i < workers.length; i++)
if (workers[i].tab == tabs.activeTab)
worker.postMessage(...);
, , script, , - . script, , .