Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 544
Xidus Avatar asked Apr 08 '13 16:04

Xidus


2 Answers

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.

like image 150
aventurin Avatar answered Sep 26 '22 22:09

aventurin


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 
like image 28
Mechanical snail Avatar answered Sep 24 '22 22:09

Mechanical snail