オンライン
実行中の Firefox セッション内では、Mozilla Add-on API を使用してデータを簡単に抽出できます。これを行う単純なTab Count Logger拡張機能を作成し、カウントを SQLite データベースに保存します。
コードの関連部分は次のとおりです。
const tabs = require("sdk/tabs");
const windows = require("sdk/windows").browserWindows;
console.log("Windows: " + windows.length + "; tabs: " + tabs.length);
オフライン
開いたタブはsessionstore.js
、SQLite ではなくプロファイル ディレクトリに保存されます。このファイルは JSON です。タブをカウントするスクリプト:
#!/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))))
これを に保存すると~/bin/firefox_count_tabs
、すべてのプロファイルの情報を次のように取得できます。
for i in ~/.mozilla/firefox/*.*; do test -d $i && (echo "== $i =="; cd $i; ~/bin/firefox_count_tabs ); done