Skip to content
This repository has been archived by the owner. It is now read-only.

Prevent js errors due to browser storage setItem / removeItem when browser in privacy mode #31

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
3 participants
@larrymyers
Copy link

larrymyers commented Oct 3, 2012

If mobile safari is in privacy mode attempting to call setItem or removeItem on localStorage and sessionStorage will throw a js error:

QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.

@cubiq

This comment has been minimized.

Copy link
Owner

cubiq commented Oct 3, 2012

this is something I wanted to implement, but I'd like a solution where you check if the browser is in privacy mode once, set a variable and act accordingly in the rest of the script

@larrymyers

This comment has been minimized.

Copy link
Author

larrymyers commented Oct 3, 2012

So the interesting thing is that window.localStorage exists in privacy mode, and you actually have to attempt to call setItem to find out if you can store data. getItem works fine, but will always return null in privacy mode.

There really is no good way to go about detection beyond trying to call the action methods on localStorage.

@cubiq

This comment has been minimized.

Copy link
Owner

cubiq commented Oct 3, 2012

couldn't we try/catch once at the beginning? try/catch makes me itchy. Also if we just try/catch we do not have a vision if the script is actually working.

@larrymyers

This comment has been minimized.

Copy link
Author

larrymyers commented Oct 6, 2012

Certainly possible to put some handling in the catch blocks on fail, the immediate desire here was to just not get js errors when somebody visits our mobile site in privacy mode.

@cubiq cubiq referenced this pull request Jan 18, 2013

Closed

Issue with private browsing #19

@gpoitch

This comment has been minimized.

Copy link

gpoitch commented Oct 1, 2013

@cubiq cubiq closed this Apr 29, 2014

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.