In Mozilla Firefox, how do I extract the number of currently opened tabs to save elsewhere?

11,870

Solution 1

@Xidus: History and bookmarks are stored in the places.sqlite. You cannot determine tabs and windows information here.tabs and windows information are stored in the sessionstore.js file.You can refer this links:

http://kb.mozillazine.org/sessionstore.js http://forums.mozillazine.org/viewtopic.php?f=38&t=622036&start=60&p=12098147#p12098147

Solution 2

Open the about:telemetry link in Firefox and click scalars tab from the sidebar menu. Alternatively, opening about:telemetry#scalars-tab will take you directly to the scalars tab.

The browser.engagement.max_concurrent_tab_count key will show the number of tabs active for the session, but does not update when a tab is closed. Instead, if you want to update this value you will need to restart your browser.

The browser.engagement.tab_open_event_count key shows the current number of open tabs at a given time and is updated dynamically.

Solution 3

Online

Within a running Firefox session, it's easy to extract the data using the Mozilla Add-on API. I wrote a simple Tab Count Logger extension that does this, and saves the count to an SQLite database.

The relevant part of the code is:

const tabs = require("sdk/tabs");
const windows = require("sdk/windows").browserWindows;

console.log("Windows: " + windows.length + "; tabs: " + tabs.length);

Offline

Opened tabs are stored in sessionstore.js in the profile directory, not in SQLite. This file is JSON. A script to count tabs:

#!/usr/bin/env python3
# Count open tabs from a firefox profile
# Working directory is the root of a Firefox profile.
import json
j = json.loads(open("sessionstore.js", 'rb').read().decode('utf-8'))
def info_for_tab(tab):
    try:
        return (tab['entries'][0]['url'], tab['entries'][0]['title'])
    except IndexError:
        return None
    except KeyError:
        return None
def tabs_from_windows(window):
    return list(map(info_for_tab, window['tabs']))
all_tabs = list(map(tabs_from_windows, j['windows']))
print('Statistics: {wins} windows, {tabs} total tabs'.format(wins=len(all_tabs), tabs=sum(map(len, all_tabs))))

After having saved this to ~/bin/firefox_count_tabs, you can get the information for all your profiles as in:

for i in ~/.mozilla/firefox/*.*; do test -d $i && (echo "== $i =="; cd $i; ~/bin/firefox_count_tabs ); done

Solution 4

The count will be shown on the exit confirm dialog - if you hadn't disable that 😂️

Solution 5

You could count tabs in the Browser Console (not Web Console) with

gBrowser.tabs.length

The Browser Console is disabled by default. To enable it you should tick an option "Enable browser chrome and add-on debugging toolboxes" in the Web Developer Tools settings. After that look for Browser Console in the More tools menu.

enter image description here

Share:
11,870

Related videos on Youtube

Xidus
Author by

Xidus

Updated on September 15, 2022

Comments

  • Xidus
    Xidus 3 months

    I want to automatically count the number of tabs that are open in Firefox so that I can track this over time.

    It is therefore not enough that I can get an add-on that displays the current number in the status bar or somewhere else in the browser.

    I have looked at the content of the .sqlite tables that firefox saves for each profile, but I have not been able to decipher whether there is a table of currently opened tabs or not. I also looked to see whether there is a column in the history table that tells whether the page is currently open or not.

    Is this information available in the databases at all?

    If so, where is there information stored that can be used to count the number of currently open tabs?

    If not, how do add-ons like e.g. Tab Counter find out this number? This last question I will ask of the developer, if it does not turn out to be common enough knowledge that I can get an answer here, rather than ask for it of someone who probably want you to use his or her add-on instead.

  • chow
    chow over 9 years
    @ Mechanical snail: I didi not find the add-on named Tab Count Loggerin the mozilla extensions.Which version it supports? Please let me know.
  • Sec
    Sec over 5 years
    On current firefox versions that sessionstore.js file has been moved to sessionstore-backups/recovery.js - other than that your python script works fine. See also dutherenverseauborddelatable.wordpress.com/2014/06/26/…
  • davejagoda
    davejagoda about 4 years
    This answer is nice since it is so simple. It seems to provide the maximum number of tabs which have been open which might not be the current number of tabs if you've closed any since reaching the high water mark.
  • Christopher Schultz
    Christopher Schultz almost 4 years
    This should be the accepted answer. Note that browser.engagement.max_concurrent_tab_count is reset for each session. If you want the "current" value, you can quit and restart.
  • fencepost
    fencepost over 3 years
    I could be wrong (and clearly have a problem that I need to address....), but this value may cap at 1023 - I tried opening some additional tabs and refreshing, but did not see a higher value. And this evening perhaps I should practice a bit of browser sanitation.
  • Daniel
    Daniel over 3 years
    @fencepost: It doesn't cap at 1023, mine shows 1455. I closed some tabs and the value updated after restarting the browser (restart, not refresh the tab).
  • davejagoda
    davejagoda over 3 years
    1119 open tabs currently. Closing a few hundred seems in order.
  • binki
    binki over 2 years
    Those of us who use “Restore previous session” don’t have that enabled ;-).
  • GlacJAY
    GlacJAY over 2 years
    @binki I'm using "restore previous session", and I've also enabled this, to remain myself how many tabs there 😂️