-
-
Save rmehner/b9a41d9f659c9b1c3340 to your computer and use it in GitHub Desktop.
// Credit to @steobrien from https://gist.github.com/rmehner/b9a41d9f659c9b1c3340#gistcomment-2940034 | |
// for modern browsers, this works: | |
const dbs = await window.indexedDB.databases() | |
dbs.forEach(db => { window.indexedDB.deleteDatabase(db.name) }) | |
// for older browsers, have a look at previous revisions of this gist. |
Here's a condensed one-liner if you just want something to copy and paste into your browser console:
indexedDB.databases().then(dbs => dbs.forEach(db => indexedDB.deleteDatabase(db.name)))
Safari DOES have indexedDb.databases, but can't do await
from the console. Luckily the abovementioned .then(dbs => dbs.forEach...)
is enough, since the oh so perfect Apple User interface requires you do delete EACH COLLECTION (instead of each database) and to do that you have to move the pointer to the other side of the window and click the trashcan button.
Firefox implements it only in webworkers so I guess it'll still be a lot of right-click-deletes (at least much faster than in Safari) unless you implement a helper function in a web worker (that HAS to be downloaded from the server).
Oh and if you think this means Chrome has a better implementation of indexedDbs, think again: it's significantly slower than both FF and Safari.... #webstandardsssuck #sorryfortherant
Sadly it doesn't work in Firefox Web Workers either, even if everyone says it does.. :(
const workFunc = function (data) {
const idd = indexedDB
|| webkitIndexedDB
|| mozIndexedDB;
const deletedDbs = [];
idd.databases()
.then(dbs => dbs.forEach(db => {idd.deleteDatabase(db.name); deletedDbs.push(db.name);}))
.then(function () {self.postMessage(deletedDbs)});
};
worker = new Worker(URL.createObjectURL(new Blob(["onmessage =" + workFunc.toString()], {type: "text/javascript"})));
worker.onmessage = function (deletedDbs) {
console.log('Deleted databases: '+ deletedDbs.join(','));
};
worker.onerror = function (e) {
console.log('Error? What error?', e.message, '. Oh that one!');
};
worker.postMessage('testing')
Remember to wrap the execution in an async
function.
(async () => {
const dbs = await window.indexedDB.databases();
dbs.forEach(db => { window.indexedDB.deleteDatabase(db.name) });
})();
This works fine for me on Safari. Note that you may not see the effect immediately on the dev tool until you close the browser window and open it again.
🙏🏽
Here's a condensed one-liner if you just want something to copy and paste into your browser console:
indexedDB.databases().then(dbs => dbs.forEach(db => indexedDB.deleteDatabase(db.name)))
Just commenting so that I can always find this.
@ray007 good idea, the source code of this is actually open source, maybe you find something there: https://github.com/firefox-devtools
Would be useful indeed!