I need to delete all my IndexedDB, currently I have:
const indexedDB = window.indexedDB || window.mozIndexedDB
|| window.webkitIndexedDB || window.msIndexedDB;
if (indexedDB.webkitGetDatabaseNames) {
const bases = indexedDB.webkitGetDatabaseNames();
bases.onsuccess = (event) => {
const data = event.target.result;
Object.values(data).forEach((db) => {
indexedDB.deleteDatabase(db);
});
resolve();
};
bases.onerror = reject;
}
But the webkitGetDatabaseNames()
function is undefined.
Is it possible delete all IndexedDB without use this method?
PD: I want to delete without knowing the names of IndexedDB and I need to delete from code (Javascript)
use on chrome
window.indexedDB.databases().then((r) => {
for (var i = 0; i < r.length; i++) window.indexedDB.deleteDatabase(r[i].name);
}).then(() => {
alert('All data cleared.');
});
Function call for getting names indexedDB.webkitGetDatabaseNames
is deprecated.
See the reference below:
https://github.com/dfahlander/Dexie.js/issues/532
There is also an intent to deprecate: IDBFactory webkitGetDatabaseNames
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/2fUr-3wFPKI/discussion
You can use following techinques to delete the database:
Technique 1:
As far as I can tell, one should use indexedDB.deleteDatabase:
var req = indexedDB.deleteDatabase(databaseName);
req.onsuccess = function () {
console.log("Deleted database successfully");
};
req.onerror = function () {
console.log("Couldn't delete database");
};
req.onblocked = function () {
console.log("Couldn't delete database due to the operation being blocked");
};
I can confirm that it works with PhantomJS 1.9.0 and Chrome 26.0.1410.43.
Technique 2
In theory, all you need to do to delete an IndexedDB in Chrome is:
In Windows, the file is located here:
%USERPROFILE%\AppData\Local\Google\Chrome\User Data\Default\IndexedDB
On Mac, do the following:
On Mac, the folder is located here:
/Users/[USERNAME]/Library/Application Support/Google/Chrome/Default/IndexedDB/
On Linux, the folder is located at:
/home/[USERNAME]/.config/google-chrome/Default/IndexedDB/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With