2

A noob at firefox extension development here. Is there a way to find Tab object from a given nsIDOMWindow?

let wm = Cc['@mozilla.org/appshell/window-mediator;1'].getService(Ci.nsIWindowMediator);

var windowListener =
{
  onOpenWindow: function(aWindow)
  {
    // Wait for the window to finish loading
    let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);

    domWindow.addEventListener("load", function()
    {
      domWindow.removeEventListener("load", arguments.callee, false);

      if (domWindow.document.documentElement.getAttribute("windowtype") == "navigator:browser")
      {

        // how do I find tabs?

      }
    }, false);
  },
}

wm.addListener(windowListener);

Been trying to find the documentation on MDN with no luck, mozilla #extdev channel gives me no response either :(

GantengX
  • 1,471
  • 2
  • 16
  • 28

1 Answers1

3

To get the current tab you can do:

domWindow.gBrowser.selectedTab

To get the set of all tabs you can use:

domWindow.gBrowser.tabContainer 

In here you can use tabs methods to select a specific index, etc. You can see more information in tabbrowser - XUL, Tabbed browser - Code Snippets and

Filipe Silva
  • 21,189
  • 5
  • 53
  • 68
  • was hoping to be able to do this using bootstrapped extension but I can't find any reference to it.. Will revert back to xul-based extension. Thanks – GantengX Oct 14 '13 at 03:09
  • 1
    not sure it was possible at that time, but these days there's the add-on SDK (with a high-level and a low-level APIs) that allows accessing tabs. – superjos Dec 01 '14 at 00:24