get urls of firefox tabs from firefox extension
Asked Answered
I

2

0

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

Imprimatur answered 22/6, 2009 at 18:2 Comment(0)
P
4

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);
  }
}
Patton answered 22/6, 2009 at 18:10 Comment(3)
downvote, because you should add the code snippet to your answer.Blau
Link is dead. This is exactly why we shouldn't do link only answers.Paleolith
fixed the link for now.Benzidine
R
1

When using Firefox SDK, see this:
https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/List_Open_Tabs

var tabs = require("sdk/tabs");
for (let tab of tabs)
    console.log(tab.url);

Additionally, the tabs object seems to have array interface, so you can use also the .length property:

var tabs = require("sdk/tabs");
for (var i = 0; i < tabs.length; i++)
    console.log(tabs[i].url);
Ramification answered 15/1, 2015 at 0:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.