If your drive fails and goes into read-only mode (like my Samsung 980 Pro did), Firefox may lose the usual sessionstore.js file used for restoring tabs. However, there’s still hope — Firefox stores active tabs in different files depending on its state:
- When Firefox is running → Tabs are saved in:
profile.folder\sessionstore-backups\recovery.baklz4 - When Firefox is not running → Tabs are saved in:
profile.folder\sessionstore.js
In my case, because the browser crashed with the drive,sessionstore.jsdidn’t exist. The only survivor wasrecovery.baklz4.
Thanks to user136036, who posted the Python code to handle .baklz4 .lz4 .mozlz4 .jsonlz4 .baklz4 files, I was able to bring my session back.
Use the provided Python code to decompress the file.
Needs lz4: pip install lz4
from sys import argv, exit
import os
try:
import lz4.block as lz4
except ImportError:
print("Please install lz4 via 'pip install lz4'.")
EXTENSIONS = {"1": ".lz4", "2": ".mozlz4", "3": ".jsonlz4", "4": ".baklz4"}
def check_overwrite(path):
if os.path.exists(path):
i = input(f"File {path} already exists. Overwrite? y/n\n")
if i.lower() == "y":
print("Overwriting file.")
return True
else:
print("Exiting.")
exit(1)
else:
return True
def print_info():
print(f"Usage: {argv[0]} <infile>")
print("Decompress Mozilla-LZ4 encoded <infile> or compress <infile> to Mozilla-LZ4.")
print("Output file will be put in same folder as input file.")
exit(1)
def choose_ext():
print(f"Please choose file extension:")
for k, v in EXTENSIONS.items():
print(f"{k}: {v}")
if (i := input()) in EXTENSIONS.keys():
return EXTENSIONS[i]
else:
print("Invalid extension.\nExiting")
exit(1)
def main():
if len(argv) != 2:
print_info()
else:
if not os.path.exists(argv[1]):
print_info()
else:
in_full_name = os.path.basename(argv[1])
in_folder_path = os.path.dirname(argv[1])
in_name, in_ext = os.path.splitext(argv[1]) # "search.json", ".mozlz4"
in_file_handle = open(argv[1], "rb")
if in_ext.lower() in EXTENSIONS.values():
''' Decompress '''
print(f"Trying to decompress {in_full_name}")
out_file = os.path.join(in_folder_path, f"{in_name}")
if check_overwrite(out_file):
with open(out_file, "wb") as f:
assert in_file_handle.read(8) == b"mozLz40\0"
f.write(lz4.decompress(in_file_handle.read()))
else:
''' Compress '''
print(f"Trying to compress {in_full_name}")
ext = choose_ext()
out_file = os.path.join(in_folder_path, f"{in_full_name}{ext}")
if check_overwrite(out_file):
with open(out_file, "wb") as f:
f.write(b"mozLz40\0" + lz4.compress(in_file_handle.read()))
if __name__ == '__main__':
main()python.exe .\script.py .\recovery.baklz4
Trying to decompress recovery.baklz4
python.exe .\script.py .\recovery.json
Trying to compress recovery.json
Please choose file extension:
1: .lz4
2: .mozlz4
3: .jsonlz4 ---->>> you need this one
4: .baklz4Change the compression format (recovery.baklz4) to match what Firefox expects (sessionstore.jsonlz4) and rename so it will be like this: recovery.jsonlz4 (Change the compression with the script)→ recovery.baklz4 → recovery.jsonlz4 (rename)→ sessionstore.jsonlz4
Copy the new sessionstore.jsonlz4 into your main profile folder (same folder that normally contains prefs.js, places.sqlite, etc.).
Open Firefox and click: ☰ Menu → History → Restore Previous Session.
All your tabs from the last session should now load. 🙂
- https://www.jeffersonscher.com/ffu/scrounger.html
- https://unix.stackexchange.com/questions/326897/how-to-decompress-jsonlz4-files-firefox-bookmark-backups-using-the-command-lin
- https://github.com/lz4/lz4
- https://lz4.org/
- https://www.reddit.com/r/firefox/comments/92f8of/how_do_i_restore_my_session_from_recoverybaklz4/
- https://gist.github.com/jscher2000/4403507e33df0918289619edb83f8193
- https://www.reddit.com/r/firefox/comments/pcxe8m/need_help_with_baklz4_files_and_restoring_my_old/
- https://support.mozilla.org/en-US/questions/1119692
- https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data
- https://superuser.com/questions/1814031/how-to-restore-firefox-session-from-previous-jsonlz4
- https://stackoverflow.com/questions/68756829/how-can-i-decompress-a-jsonlz4-mozilla-firefox-session-file
- https://support.mozilla.org/en-US/kb/how-restore-browsing-session-backup
- https://www.reddit.com/r/firefox/comments/92f8of/how_do_i_restore_my_session_from_recoverybaklz4/