sienori / Tab-Session-Manager

WebExtensions for restoring and saving window / tab states
https://tab-session-manager.sienori.com/
Mozilla Public License 2.0
1.87k stars 182 forks source link

Fail to import Session Buddy sessions with unnamed session #1287

Open Konnichy opened 7 months ago

Konnichy commented 7 months ago

Short description

Trying to import in TSM an export from SB, even a small a only one session, fails with error "Read failed". Investigation shows this happens when the SB export contains sessions with no name. I attach 2 versions of the same simple export, one with a session name added.

Steps to reproduce

  1. Import addedname.json
  2. Notice the "Read failed" error
  3. Import noname.json
  4. Notice the success

Expected result

Both files should import successfully. The one without session name may be named "Unnamed session" on the fly (it is display with this name in SB).

Actual result

See above.

Platform information

Konnichy commented 7 months ago

For information, I fixed an export containing 528 sessions with this Python script:

#!/usr/bin/env python3

import sys
import os
import json

if __name__ == '__main__':
    if len(sys.argv) < 2:
        print("Usage: {} <export from Session Buddy>".format(sys.argv[0]))
        exit(1)

    input_file = sys.argv[1]
    (root, ext) = os.path.splitext(input_file)
    output_file = ''.join([root, "_converted", ext])

    with open(input_file, 'r', encoding='utf-8-sig') as file:
        content = json.loads(file.read().encode())

    for session in content['sessions']:
        if 'name' not in session:
            session.update({'name': 'Unnamed session'})
        if session['created'] is None:
            if session['modified'] is not None:
                session['created'] = session['modified']
                print("Warning: Session '{}': missing creation date fixed with the last modification date.".format(session['name']))
            else:
                print("Warning: Session '{}' does not have a creation date. You may fix the file manually.".format(session['name']))

    with open(output_file, 'w', encoding='utf-8-sig') as file:
        json.dump(content, file, indent=3)