Skip to content
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

Fail more gracefully when opening IndexedDb fails in Firefox private browsing #5396

Merged
merged 7 commits into from
Sep 2, 2021

Conversation

dconeybe
Copy link
Contributor

@dconeybe dconeybe commented Aug 27, 2021

Improve the obscure failure that occurs when attempting to open an IndexedDb connection in a Firefox private browsing session (which is a known limitation of Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1639542).

Before this fix, the error that occurred in this scenario in v8.10.0 would be vague:

Uncaught (in promise) IndexedDbTransactionError: IndexedDB transaction 'getHighestListenSequenceNumber' failed: InvalidStateError: A mutation operation was attempted on a database that did not allow mutations.

In v9.0.0 it was even worse because it mislead readers to suggest that it was related to multi-tab:

Uncaught (in promise) FirebaseError: Failed to obtain exclusive access to the persistence layer. To allow shared access, multi-tab synchronization has to be enabled in all tabs. If you are using experimentalForceOwningTab:true, make sure that only one tab has persistence enabled at any given time.

With this fix, the error message becomes more helpful by specifically calling out Firefox private browsing as a potential culprit:

Uncaught (in promise) FirebaseError: Unable to open an IndexedDB connection. This could be due to running in a private browsing session on a browser whose private browsing sessions do not support IndexedDB: InvalidStateError: A mutation operation was attempted on a database that did not allow mutations.

Both before and after this fix, Firestore would continue to be functional, just without persistence.

Fixes #5377

@changeset-bot
Copy link

changeset-bot bot commented Aug 27, 2021

🦋 Changeset detected

Latest commit: dc38ea4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/firestore Patch
firebase Patch
@firebase/firestore-compat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Aug 27, 2021

Size Analysis Report

Affected Products

No changes between base commit (509c18f) and head commit (ceabb8f).

Copy link
Contributor

@schmidt-sebastian schmidt-sebastian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Can you remove the Firefox mention from the error message since we don't know where else this occurs? You can leave it in the changelog though as it addresses a specific issue.

@dconeybe
Copy link
Contributor Author

Thank you! Can you remove the Firefox mention from the error message since we don't know where else this occurs? You can leave it in the changelog though as it addresses a specific issue.

The thing is, IndexedDb works in Chrome incognito mode. So removing Firefox from the message IMO incorrectly implies that it is broken on Chrome too.

Also, the hyperlink the message is to a bug report against Firefox for IndexedDb support in private browsing mode. I'm not sure what the best wording is but I'm open to suggestions.

@schmidt-sebastian
Copy link
Contributor

I would try to be more vague and remove the link as well. You can also list it as an example of why it could be broken - but it is likely not the only reason. It would confuse users that see this error that are not on Firefox. Browsers that support private browsing with IndexedDB wouldn't show this error.

…StateError can presumably happen for other reasons as well
@dconeybe
Copy link
Contributor Author

I would try to be more vague and remove the link as well. You can also list it as an example of why it could be broken - but it is likely not the only reason. It would confuse users that see this error that are not on Firefox. Browsers that support private browsing with IndexedDB wouldn't show this error.

Done. I've changed the error message to the following:

Unable to open an IndexedDb connection. This could be due to running in a private browsing session on a browser whose private browsing sessions do not support IndexedDb. (InvalidStateError: A mutation operation was attempted on a database that did not allow mutations.)

'Firefox private browsing session, in which IndexedDb is not supported ' +
'(https://goo.gle/3ymSNyf): ' +
error
'Unable to open an IndexedDb connection. This could be due to running in a ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The official spelling seems to be IndexedDB.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Code.FAILED_PRECONDITION,
'Unable to open an IndexedDb connection. This could be due to running in a ' +
'private browsing session on a browser whose private browsing sessions do not ' +
'support IndexedDb. (' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think you should move the period after the parenthesis or use : without parenthesis.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (changed to ":").

@dconeybe dconeybe merged commit 8180a2b into master Sep 2, 2021
@dconeybe dconeybe deleted the dconeybe/FixFirefoxPrivateBrowsingIndexedDb branch September 2, 2021 20:14
@google-oss-bot google-oss-bot mentioned this pull request Sep 7, 2021
@firebase firebase locked and limited conversation to collaborators Oct 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FIrefox Private Browsing: A mutation operation was attempted on a database that did not allow mutations
3 participants