This guide explains how to extract a list of all open tabs from Firefox or LibreWolf using a small Python script. Useful for backups, migrating sessions, or just getting a quick overview of what you have open on another computer accessed over ssh.
How It Works
Firefox-based browsers store session data in a file called recovery.jsonlz4 — a JSON blob compressed with Mozilla’s variant of LZ4. The script decompresses it, walks the session structure, and prints the current URL and title for each open tab.
Prerequisites
You need the lz4 Python package:
pip install lz4The Script
Save this as extract_tabs.py:
import json, lz4.block, sys
with open(sys.argv[1], "rb") as f:
magic = f.read(8) # skip the "mozLz40\0" header
data = json.loads(lz4.block.decompress(f.read()))
for window in data.get("windows", []):
for tab in window.get("tabs", []):
entries = tab.get("entries", [])
if entries:
current = entries[tab.get("index", len(entries)) - 1]
print(current.get("url"), "-", current.get("title", ""))How It Works:
- Reads the
.jsonlz4file and skips the 8-byte magic header (mozLz40\0). - Decompresses the LZ4 payload and parses the JSON.
- Iterates over all windows and tabs in the session.
- Prints the URL and title of each tab’s current history entry.
Usage
Firefox
python extract_tabs.py "$(find ~/.mozilla/firefox/ -name "recovery.jsonlz4")"LibreWolf
python extract_tabs.py "$(find ~/.librewolf/ -name "recovery.jsonlz4")"Tips
- The session file is only present while the browser is running (or was recently closed). If you don’t find it, look for
previous.jsonlz4as a fallback. - Pipe through
grepto filter for specific domains:python extract_tabs.py ... | grep github.com - Redirect to a file for a quick backup:
python extract_tabs.py ... > tabs.txt