Skip to content

Gracefully fall back to memory persistence for Firefox Private Browsing. #1801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ import { ViewSnapshot } from './view_snapshot';

const LOG_TAG = 'FirestoreClient';

/** The DOMException code for an aborted operation. */
/** DOMException error code constants. */
const DOM_EXCEPTION_INVALID_STATE = 11;
const DOM_EXCEPTION_ABORTED = 20;

/** The DOMException code for quota exceeded. */
const DOM_EXCEPTION_QUOTA_EXCEEDED = 22;

export class IndexedDbPersistenceSettings {
Expand Down Expand Up @@ -255,8 +254,8 @@ export class FirestoreClient {
}

console.warn(
'Error enabling offline storage. Falling back to' +
' storage disabled: ' +
'Error enabling offline persistence. Falling back to' +
' persistence disabled: ' +
error
);
return this.startMemoryPersistence();
Expand Down Expand Up @@ -285,15 +284,22 @@ export class FirestoreClient {
typeof DOMException !== 'undefined' &&
error instanceof DOMException
) {
// We fall back to memory persistence if we cannot write the primary
// lease. This can happen can during a schema migration, or if we run out
// of quota when we try to write the primary lease.
// For both the `QuotaExceededError` and the `AbortError`, it is safe to
// fall back to memory persistence since all modifications to IndexedDb
// failed to commit.
// There are a few known circumstances where we can open IndexedDb but
// trying to read/write will fail (e.g. quota exceeded). For
// well-understood cases, we attempt to detect these and then gracefully
// fall back to memory persistence.
// NOTE: Rather than continue to add to this list, we could decide to
// always fall back, with the risk that we might accidentally hide errors
// representing actual SDK bugs.
return (
// When the browser is out of quota we could get either quota exceeded
// or an aborted error depending on whether the error happened during
// schema migration.
error.code === DOM_EXCEPTION_QUOTA_EXCEEDED ||
error.code === DOM_EXCEPTION_ABORTED
error.code === DOM_EXCEPTION_ABORTED ||
// Firefox Private Browsing mode disables IndexedDb and returns
// INVALID_STATE for any usage.
error.code === DOM_EXCEPTION_INVALID_STATE
);
}

Expand Down