@@ -65,10 +65,9 @@ import { ViewSnapshot } from './view_snapshot';
65
65
66
66
const LOG_TAG = 'FirestoreClient' ;
67
67
68
- /** The DOMException code for an aborted operation. */
68
+ /** DOMException error code constants. */
69
+ const DOM_EXCEPTION_INVALID_STATE = 11 ;
69
70
const DOM_EXCEPTION_ABORTED = 20 ;
70
-
71
- /** The DOMException code for quota exceeded. */
72
71
const DOM_EXCEPTION_QUOTA_EXCEEDED = 22 ;
73
72
74
73
export class IndexedDbPersistenceSettings {
@@ -255,8 +254,8 @@ export class FirestoreClient {
255
254
}
256
255
257
256
console . warn (
258
- 'Error enabling offline storage . Falling back to' +
259
- ' storage disabled: ' +
257
+ 'Error enabling offline persistence . Falling back to' +
258
+ ' persistence disabled: ' +
260
259
error
261
260
) ;
262
261
return this . startMemoryPersistence ( ) ;
@@ -285,15 +284,22 @@ export class FirestoreClient {
285
284
typeof DOMException !== 'undefined' &&
286
285
error instanceof DOMException
287
286
) {
288
- // We fall back to memory persistence if we cannot write the primary
289
- // lease. This can happen can during a schema migration, or if we run out
290
- // of quota when we try to write the primary lease.
291
- // For both the `QuotaExceededError` and the `AbortError`, it is safe to
292
- // fall back to memory persistence since all modifications to IndexedDb
293
- // failed to commit.
287
+ // There are a few known circumstances where we can open IndexedDb but
288
+ // trying to read/write will fail (e.g. quota exceeded). For
289
+ // well-understood cases, we attempt to detect these and then gracefully
290
+ // fall back to memory persistence.
291
+ // NOTE: Rather than continue to add to this list, we could decide to
292
+ // always fall back, with the risk that we might accidentally hide errors
293
+ // representing actual SDK bugs.
294
294
return (
295
+ // When the browser is out of quota we could get either quota exceeded
296
+ // or an aborted error depending on whether the error happened during
297
+ // schema migration.
295
298
error . code === DOM_EXCEPTION_QUOTA_EXCEEDED ||
296
- error . code === DOM_EXCEPTION_ABORTED
299
+ error . code === DOM_EXCEPTION_ABORTED ||
300
+ // Firefox Private Browsing mode disables IndexedDb and returns
301
+ // INVALID_STATE for any usage.
302
+ error . code === DOM_EXCEPTION_INVALID_STATE
297
303
) ;
298
304
}
299
305
0 commit comments