2
votes

I'm trying to dump all data stored by an Firefox extension using IndexedDB.

Due to some problem of Firefox Indexed DB API (see buglist https://github.com/sienori/Tab-Session-Manager/issues/364), all my firefox tabs/windows stored using the extension tab session manager totally disapears after upgrade of plugin/firefox ...

I'm not alone in this case. There are some strategy to restore data given by developper, but any of them work in my case.

Tabs/Windows saved by this extension are stored using an SQLITE file, located in my firefox profile : .../2y6ybf92.default/storage/default/moz-extension+++eddda785-9abb-4c35-8b00-921325674952/idb/1782160246ssensosi.sqlite

Database can be opened using DB Browser for SQLITE, so i suppose database is not corrupted. But i'm not sure because, as you imagine, data is stored in binary format....

I try to dump the database using dexie.js library and this example : https://github.com/dfahlander/Dexie.js/blob/master/samples/open-existing-db/dump-databases.html

 console.log("Dumping Databases");
        console.log("=================");
        Dexie.getDatabaseNames(function (databaseNames) {
            if (databaseNames.length === 0) {
                // No databases at this origin as we know of.
                console.log("There are no databases at current origin. Try loading another sample and then go back to this page.");
            } else {
                // At least one database to dump
                dump(databaseNames);
            }
            function dump(databaseNames) {
                if (databaseNames.length > 0) {
                    var db = new Dexie(databaseNames[0]);
                    // Now, open database without specifying any version. This will make the database open any existing database and read its schema automatically.
                    db.open().then(function () {
                        console.log("var db = new Dexie('" + db.name + "');");
                        console.log("db.version(" + db.verno + ").stores({");
                        db.tables.forEach(function (table, i) {
                            var primKeyAndIndexes = [table.schema.primKey].concat(table.schema.indexes);
                            var schemaSyntax = primKeyAndIndexes.map(function (index) { return index.src; }).join(',');
                            console.log("    " + table.name + ": " + "'" + schemaSyntax + "'" + (i < db.tables.length - 1 ? "," : ""));
                            // Note: We could also dump the objects here if we'd like to:
                            //  table.each(function (object) {
                            //      console.log(JSON.stringify(object));
                            //  });
                        });
                        console.log("});\n");
                    }).finally(function () {
                        db.close();
                        dump(databaseNames.slice(1));
                    });;
                } else {
                    console.log("Finished dumping databases");
                    console.log("==========================");
                }
            }
        });

Dexie return "no existing database" using Firefox, and Chrome for a sqlite file located in the same folder of the dump-database page ...

Is there a way to open directly the .sqlite file using dexie ?

Do you think possible to dump and convert in readable format all (binary) data stored by indexed Db in this sqlite file using dexie.js ? If no, is there any other solution to retrieve my data ?

1
Open the database in the standard sqlite3 shell and use .dump.Shawn
@Shawn yes, this is not really the problem, data i get in export is blob binary. I correct the title of my question.reyman64

1 Answers

0
votes

Dexie.js has a code sample that is designed to be used to dump IndexDB. It can be found on Github

The issue you're running into will happen with that code as well, though. Unfortunately Dexie.getDatabaseNames() will list all databases only for chromium browsers. Non-Chromium browsers will only see databases created with Dexie. This enumeration does not limit access, though. If you know the name of the other DB you can try to get it directly as explained here.

let db = await new Dexie("name-of-pouch-db").open();
console.log("Version", db.verno);
console.log("Tables", db.tables.map(({name, schema}) => ({
  name,
  schema
}));

If you can successfully load the IndexDB with Dexie by name, then you can use the Dexie Plugin, dexie-export-import, to handle your dump and restore operations.