Skip to content

Don't error if user has disabled all site storage in their browser#924

Merged
baltpeter merged 1 commit intomasterfrom
b_graceful-disabled-cookies
Aug 16, 2022
Merged

Don't error if user has disabled all site storage in their browser#924
baltpeter merged 1 commit intomasterfrom
b_graceful-disabled-cookies

Conversation

@baltpeter
Copy link
Copy Markdown
Member

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.

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.
@baltpeter baltpeter added the bug Something isn't working label Aug 16, 2022
@cypress
Copy link
Copy Markdown

cypress bot commented Aug 16, 2022



Test summary

67 0 8 0Flakiness 0


Run details

Project datenanfragen/website
Status Passed
Commit 6ebee8c
Started Aug 16, 2022 5:28 PM
Ended Aug 16, 2022 5:31 PM
Duration 03:08 💡
OS Linux Debian - 10.9
Browser Electron 91

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

Copy link
Copy Markdown
Member

@mal-tee mal-tee left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@baltpeter baltpeter merged commit 6ec517e into master Aug 16, 2022
@baltpeter baltpeter deleted the b_graceful-disabled-cookies branch August 16, 2022 19:52
@mal-tee
Copy link
Copy Markdown
Member

mal-tee commented Apr 3, 2024

Do we have a regression here? We just got this error report:

message := Uncaught UnknownError: The user denied permission to access the database.
type := error
colno := 18078
filename := https://www.datarequests.org/js/commons.bundle.gen.js
lineno := 19
error.code := 0
error.message := The user denied permission to access the database.
error.description := Unexpected error while opening IndexedDB in PrivacyAsyncStorage.getDb
[error.name](http://error.name/) := UnknownError
error.enduser_message := An unexpected error occured while trying to access the database in your browser.
error.context.options.storeName := proceedings
[error.context.options.name](http://error.context.options.name/) := Datenanfragen.de

@baltpeter
Copy link
Copy Markdown
Member Author

@mal-tee The problem was probably that this PR only sets the default but not the dnt default. So if the user had enabled DNT and disabled cookies, this error can occur.

This will be fixed in #1166, though I guess that doesn't matter too much anymore since Firefox has since removed DNT support…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Development

Successfully merging this pull request may close these issues.

2 participants