Reputation: 161
Firefox browser element does not return page title when tabs are loaded from previous session. The code I use:
var browsers = gBrowser.browsers;
for (var i = 0, len = browsers.length; i < len; i++) {
dump('page title #1: ' + browsers[i].contentTitle + '\n'); // here I get no title
dump('page title #2: ' + browsers[i].contentDocument.title + '\n'); // nothing here
dump('url: ' + browsers[i].contentDocument.location + '\n'); // url is fully loaded here
}
So the question is: how do I get the page title? Pages start loading when I activate the tab. But page title is shown in the tab list right after the browser starts.
Upvotes: 0
Views: 252
Reputation: 57681
The issue is that the pages are really not restored. The tabs have about:blank
loaded into them and the real page only starts loading when the user goes to the tab. So contentDocument.title
cannot have any meaningful value.
What you apparently want is the title displayed on the tab - it doesn't reflect what is loaded into the tab, it's rather something remembered from the previous session. So you should actually get the tab title, something like this:
var tabs = gBrowser.tabs;
for (var i = 0, len = tabs.length; i < len; i++) {
dump('page title: ' + tabs[i].label + '\n');
}
Upvotes: 1