22

I'm using IndexedDB in a Windows 8 app and I'm very new to both. I've been able to successfully create, read, update, delete objects from object stores, and have created a couple databases and a few object stores. My question is how can I list all of my object stores and databases? I create a few bogus ones that are not needed and I would like to clean things up a bit, but I can't remember what they are named. Maybe this is anal retentive, but it seems like it should be possible to list all databases and stores. Thanks!

devhammer
  • 1,384
  • 1
  • 8
  • 15
skinneejoe
  • 3,921
  • 5
  • 30
  • 45

4 Answers4

40

At the time of writing this post [chrome 72], You can list all the databases using following command in console of the browser. Essentially indexedDB.databases() is a Promise. You can use it to get list of all databases as an array. Run a loop on the array to get the names of databases.

indexedDB.databases().then(r => console.log(r))

Hope this helps

mdsadiq
  • 788
  • 1
  • 9
  • 11
  • `indexedDB.databases()` can also be used programmatically in Chrome – Velojet Feb 20 '20 at 07:54
  • 5
    MDN reference: [`IDBFactory.databases`](https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory/databases). Note limited browser support. – medmunds Apr 15 '20 at 19:33
20

EDIT 2018 This answer is no longer applicable:

webkitGetDatabaseNames() is deprecated in chrome 60


In Chrome webkit there was a function which would return all database names, this function is no longer available as of Chrome 60 (webkitgetdatabasenames):

indexedDB.webkitGetDatabaseNames().onsuccess = function(sender,args) { 
  console.log(sender.target.result); 
};

And there is another function which list all object stores in a single database which work in all browsers:

indexedDB.open(databaseName).onsuccess = function(sender, args) { 
  console.log(sender.target.result.objectStoreNames); 
};
Raine Revere
  • 30,985
  • 5
  • 40
  • 52
Deni Spasovski
  • 4,004
  • 3
  • 35
  • 52
  • 3
    [`webkitGetDatabaseNames()` is deprecated in chrome 60](https://developers.google.com/web/updates/2017/06/chrome-60-deprecations#remove_indexeddbwebkitgetdatabasenames) – xkeshav Oct 02 '17 at 05:43
14

There is currently no way of enumerating the existing databases in the standard. Windows 8 apps use IE, which does not provide the non-standard webkitGetDatabaseNames method. You might be able to clear the databases using the options dialog in IE10.

Listing the stores inside a database is defined in the standard using the objectStoreNames method of an IDBDatabase instance.

Useless Code
  • 12,123
  • 5
  • 35
  • 40
  • 1
    Correct, and I think it would dangerous to have a getDatabaseNames method. This way hackers would have the ability to easily search for db's existing on the clients. – Kristof Degrave Mar 06 '13 at 13:40
  • 2
    @KristofDegrave no that's not an issue because you can't do cross domain access to an indexedDB. – user1133275 May 12 '17 at 14:48
  • 1
    @user1133275 The same-origin policy doesn't necessarily protect you from an attacker being able to access it via XSS. If they inject a script into your page via something like SQL injection, their script would run locally in the page and be able to access it and then send that information somewhere else. – Useless Code May 13 '17 at 10:25
5

Since all other topics reference back here as a duplicates. In Chrome you can view and delete all created databases in Developer Tools > Application > Storage.

To view IndexedDB internals: chrome://indexeddb-internals/

holmberd
  • 2,393
  • 26
  • 30