Created
April 17, 2023 02:04
-
-
Save clovelt/3c161f51acb4c9fdb1c54a438f821821 to your computer and use it in GitHub Desktop.
Firefox download IndexedDB data through console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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