Search code examples
firefoxfirefox-addonfirefox-addon-sdk

Get window object from tab


I am developing an extension on Firefox's Addon SDK (v1.10).

My extension has a toolbarbutton that updates a small badge to its left based on the contents of the active tab.

Problem

When there is more than one window open, the toolbarbutton gets updated to the value of the active tab, regardless of whether or not it is on the same window. This means that the non active window's toolbarbutton is getting updated with data coming from a different window.

Having access to the tab object from where the data comes from, is there a way to identify the window object the tab is attached to?

It would be the opposite of this method described here.


Solution

  • Looking at the SDK source code (namely packages/api-utils/lib/tabs/tab.js), a tab object actually has a window property. I tested it and this works indeed:

    console.log(require("tabs").activeTab.window.title);
    

    Not sure why this property isn't documented, probably a documentation bug.