Search code examples
javascriptfirefoxfirefox-addonfirefox-addon-sdkmozilla

Get message manager of a tab? (Firefox Add-on SDK)


It is a Firefox add-on SDK.

I want to load a frame script to a given browser tab (complying with e10s).

Currently I try to do this for every tab (just for testing), but message manager is undefined. Why?

var self = require("sdk/self");
var { setTimeout} = require ("sdk/timers");
var { viewFor } = require("sdk/view/core");

function myFunc() {
  var tabs = require("sdk/tabs");
  for (let tab of tabs) {
    console.log(tab.title);
    var xulTab = viewFor(tab);
    console.log(xulTab.messageManager);
    console.log(tab.messageManager);
  } 
}

Both log print out undefined

I need messageManager object in order to call loadFrameScript function afterwards. Thank you very much!


Solution

  • Excellent question. This is e10s safe:

    var mm = xulTab.linkedBrowser.messageManager

    Then you can use it as normal such as: mm.sendAsyncMessage(....)