Skip to content

Instantly share code, notes, and snippets.

@clovelt
Created April 17, 2023 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clovelt/3c161f51acb4c9fdb1c54a438f821821 to your computer and use it in GitHub Desktop.
Save clovelt/3c161f51acb4c9fdb1c54a438f821821 to your computer and use it in GitHub Desktop.
Firefox download IndexedDB data through console
const dbName = prompt("Enter the name of the database:");
const request = indexedDB.open(dbName);
request.onerror = function(event) {
console.error("Could not open database", event.target.errorCode);
};
request.onsuccess = function(event) {
const db = event.target.result;
const objectStoreNames = Array.from(db.objectStoreNames);
const data = {};
const transaction = db.transaction(objectStoreNames, "readonly");
transaction.onerror = function(event) {
console.error("Could not retrieve data from object stores");
};
objectStoreNames.forEach(function(objectStoreName) {
const objectStore = transaction.objectStore(objectStoreName);
const objectStoreData = [];
objectStore.openCursor().onsuccess = function(event) {
const cursor = event.target.result;
if (cursor) {
objectStoreData.push(cursor.value);
cursor.continue();
} else {
data[objectStoreName] = objectStoreData;
if (Object.keys(data).length === objectStoreNames.length) {
const json = JSON.stringify(data, null, 2);
const blob = new Blob([json], { type: "application/json" });
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = `${dbName}.json`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
};
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment