As far as I know, there is no built-in getTabForBrowser function, so you have to minimize it yourself. However, your code assumes that the browser nodes are stored in the same DOM order as the tab nodes. I canβt say for sure if this assumption is ever broken, but given that the tabs can be moved by the user arbitrarily, this is not what I would rely on.
Fortunately, each tab object has a linkedBrowser property. Therefore, you can rewrite your code like this:
gBrowser.getTabForBrowser = function(browser) { var mTabs = gBrowser.mTabContainer.childNodes; for (var i=0, i<mTabs.length; i++) { if (mTabs[i].linkedBrowser == browser) { return mTabs[i]; } } return null; }
source share