Skip to content

Instantly share code, notes, and snippets.

@dfahlander
Last active October 6, 2025 20:20
Show Gist options
  • Select an option

  • Save dfahlander/6c1980a0b934f3d16c97c0835fa6113b to your computer and use it in GitHub Desktop.

Select an option

Save dfahlander/6c1980a0b934f3d16c97c0835fa6113b to your computer and use it in GitHub Desktop.
Export-IndexedDB-using-devtools-console
// On any web page that stores things in IndexedDB,
// open devtools and in the console, write the following:
script1 = document.createElement('script');
script1.src = 'https://unpkg.com/[email protected]';
document.body.appendChild(script1);
script2 = document.createElement('script');
script2.src = 'https://unpkg.com/[email protected]';
document.body.appendChild(script2);
// In devtools "applications" tab navigate to IndexedDB and find
// the name of the databases to export. Then write:
theDBName = 'the name of the database you want to export';
// Export the database into a Blob:
theDB = new Dexie(theDBName);
let {verno, tables} = await theDB.open();
theDB.close();
theDB = new Dexie(theDBName);
theDB.version(verno).stores(tables.reduce((p,c) => {p[c.name] = c.schema.primKey.keyPath || ""; return p;}, {}));
theBlob = await theDB.export();
@frumbert
Copy link

frumbert commented Jan 6, 2023

Try using dynamic imports. Just modify the db name at the start.

        const theDBName = 'YourDatabase';
        (async () => {
            await import('https://unpkg.com/[email protected]');
            await import('https://unpkg.com/[email protected]');
            await import('https://unpkg.com/downloadjs');
            let theDB = new Dexie(theDBName);
            let {verno, tables} = await theDB.open();
            theDB.close();
            theDB = new Dexie(theDBName);
            theDB.version(verno).stores(tables.reduce((p,c) => {p[c.name] = c.schema.primKey.keyPath || ""; return p;}, {}));
            theBlob = await theDB.export();
            download(theBlob, `${theDBName}.json`, "application/json")
        })();

@recrof
Copy link

recrof commented Sep 24, 2025

dynamic imports + save all databases:

await import('https://unpkg.com/[email protected]');
await import('https://unpkg.com/[email protected]');

const dbs = await indexedDB.databases();
for(const db of dbs) {
  console.log('exporting', db);
  let dexie = new Dexie(db.name);
  const {verno, tables} = await dexie.open();
  dexie.close();
  dexie = new Dexie(db.name);
  dexie.version(verno).stores(tables.reduce((p,c) => {p[c.name] = c.schema.primKey.keyPath || ""; return p;}, {}));
  const exportBlob = await dexie.export();
  const aEl = document.createElement('a');
  aEl.href = URL.createObjectURL(exportBlob);
  aEl.download = `${db.name}.json`;
  aEl.click();
}

@pianosaurus
Copy link

Importing a file exported using any of the above methods (assuming you can serve it, example uses localhost:8080):

await import('https://unpkg.com/[email protected]');
await import('https://unpkg.com/[email protected]');

data = await fetch('http://localhost:8080/db-name.json').then((r) => r.blob());
dexie = await DexieExportImport.peakImportFile(data);

Database name is restored from file, and doesn't have to be specified.

You can replace r.blob() with r.json() to get an object, if you want access to the data without actually restoring anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment