Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if IndexedDB is enabled

I'm wondering how to detect in JavaScript, whether or not IndexedDB is available and enabled.

I'm currently doing a test along these lines:

if (window.indexedDB) {
    if ((using_chrome && browserVersion >= 24)
        || (usingFirefox && browserVersion >= 16)
        || (usingIe && browserVersion >= 10)
        || (usingEdge && browserVersion >= 12)
        || (usingSafari && browserVersion >= 9)) {
        accessible = true;
    } 
} 

But I would much prefer to use feature detection than relying on version numbers.

Assuming that feature detection for testing IndexedDB is efficient, does anyone know of a good way to test this on page load?

like image 713
Marc Avatar asked Sep 03 '25 04:09

Marc


1 Answers

You can check it using Modernizr:

if (Modernizr.indexeddb) {
  console.log("IndexedDB is supported.");
} else {
  console.log("IndexedDB is not supprorted.");
}

Note that almost all modern browser support IndexedDB now (see caniuse.com).

like image 133
Michał Perłakowski Avatar answered Sep 05 '25 00:09

Michał Perłakowski