Don't error if user has disabled all site storage in their browser#924
Merged
Don't error if user has disabled all site storage in their browser#924
Conversation
We received an error report where most of our pages were unusable due to a "No available storage method found" error from localForage. As the message implies, this error occurs if the user has disabled _all_ site storage in their browser and localForage can't find any backend to write to. I was able to reproduce this both in Chrome and Firefox. In Chrome, you can disable all site storage by going to chrome://settings/cookies and choosing "Block all cookies (not recommended)". In Firefox, it's more hidden and per-site. Open the site and press Ctrl + I to open the "Page Info" dialog. Click "Permissions" and disable "Set cookies". Obviously, disabling site storage shouldn't make our site fail. After all, we even explicitly allow users to turn that off on our site! Thus, the solution is quite simple: Instead of defaulting to "true" for the corresponding privacy controls, we should default according to whether the user has enabled site storage. Since all browsers seem to tie disabling localStorage et al. to disabling cookies, we can just check whether cookies are enabled for this feature detection and there's the very handy `navigator.cookieEnabled` property for that.
Test summaryRun details
View run in Cypress Dashboard ➡️ This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard |
Member
|
Do we have a regression here? We just got this error report: |
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We received an error report where most of our pages were unusable due
to a "No available storage method found" error from localForage. As the
message implies, this error occurs if the user has disabled all site
storage in their browser and localForage can't find any backend to
write to.
I was able to reproduce this both in Chrome and Firefox. In Chrome, you
can disable all site storage by going to chrome://settings/cookies and
choosing "Block all cookies (not recommended)". In Firefox, it's more
hidden and per-site. Open the site and press Ctrl + I to open the "Page
Info" dialog. Click "Permissions" and disable "Set cookies".
Obviously, disabling site storage shouldn't make our site fail. After
all, we even explicitly allow users to turn that off on our site! Thus,
the solution is quite simple: Instead of defaulting to "true" for the
corresponding privacy controls, we should default according to whether
the user has enabled site storage.
Since all browsers seem to tie disabling localStorage et al. to
disabling cookies, we can just check whether cookies are enabled for
this feature detection and there's the very handy
navigator.cookieEnabledproperty for that.