supportsIndexedDb static method

Future<bool> supportsIndexedDb({
  1. bool inWebWorker = false,
})

Attempts to check whether the current browser supports the DriftWebStorage.indexedDb storage implementation.

Implementation

static Future<bool> supportsIndexedDb({bool inWebWorker = false}) async {
  var isIndexedDbSupported = false;
  if (inWebWorker && WorkerGlobalScope.instance.indexedDB != null) {
    isIndexedDbSupported = true;
  } else {
    try {
      isIndexedDbSupported = IdbFactory.supported;

      if (isIndexedDbSupported) {
        // Try opening a mock database to check if IndexedDB is really
        // available. This avoids the problem with Firefox incorrectly
        // reporting IndexedDB as supported in private mode.
        final mockDb = await window.indexedDB!.open('drift_mock_db');
        mockDb.close();
      }
    } catch (error) {
      isIndexedDbSupported = false;
    }
  }
  return isIndexedDbSupported && context.hasProperty('FileReader');
}