In a firefox extension, how do you enumerate the current window's tabs and retrieve their URLs?
get urls of firefox tabs from firefox extension
Asked Answered
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);
}
}
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
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);
© 2022 - 2024 — McMap. All rights reserved.