Search code examples
firefoxfirefox-addon

get urls of firefox tabs from firefox extension


In a firefox extension, how do you enumerate the current window's tabs and retrieve their URLs?


Solution

  • There's a code snippet at MDC that does exactly that:

    var num = gBrowser.browsers.length;
    for (var i = 0; i < num; i++) {
      var b = gBrowser.getBrowserAtIndex(i);
      try {
        dump(b.currentURI.spec); // dump URLs of all open tabs to console
      } catch(e) {
        Components.utils.reportError(e);
      }
    }