javascriptbrowser-feature-detection

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?


Solution

  • 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).