Saturday, 4 January 2020

How to dump and convert binary blob for an Indexed DB sqlite database from Firefox extension

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 ?



from How to dump and convert binary blob for an Indexed DB sqlite database from Firefox extension

No comments:

Post a Comment