Skip to content

Instantly share code, notes, and snippets.

@zb3
Created April 8, 2023 20:07
Show Gist options
  • Save zb3/a8eec725fd5d54d33995c25f7945c93c to your computer and use it in GitHub Desktop.
Save zb3/a8eec725fd5d54d33995c25f7945c93c to your computer and use it in GitHub Desktop.
Get open tabs in Fenix on Android
# tested on fenix 107
# obviously requires root
import json
import datetime
import sys
if len(sys.argv) > 1:
tab_files = [sys.argv[1]]
else:
tab_files = [
'/data/data/org.mozilla.firefox/files/mozilla_components_session_storage_gecko.json',
'/data/data/org.mozilla.firefox_beta/files/mozilla_components_session_storage_gecko.json'
]
for fname in tab_files:
try:
with open(fname, 'r') as f:
data = json.load(f)
break
except FileNotFoundError:
pass
sessions = data['sessionStateTuples']
sessions = sorted(sessions, key=lambda s: s['session']['createdAt'])
for session in sessions:
session_data = session['session']
title = session_data['title']
url = session_data['url']
timestamp = session_data['createdAt'] / 1000 # convert milliseconds to seconds
date_str = datetime.datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
print(title)
print(url)
print(date_str)
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment