My webapp have javascript errors in ios safari private browsing:
JavaScript:error
undefined
QUOTA_EXCEEDED_ERR:DOM Exception 22:An attempt was made to add something to storage...
my code:
localStorage.setItem('test',1)
My webapp have javascript errors in ios safari private browsing:
JavaScript:error
undefined
QUOTA_EXCEEDED_ERR:DOM Exception 22:An attempt was made to add something to storage...
my code:
localStorage.setItem('test',1)
Here's a solution for AngularJS using an IIFE and leveraging the fact that services are singletons.
This results in
isLocalStorageAvailable
being set immediately when the service is first injected and avoids needlessly running the check every time local storage needs to be accessed.I just created this repo to provide
sessionStorage
andlocalStorage
features for unsupported or disabled browsers.Supported browsers
How it works
It detects the feature with the storage type.
Sets
StorageService.localStorage
towindow.localStorage
if it is supported or creates a cookie storage. SetsStorageService.sessionStorage
towindow.sessionStorage
if it is supported or creates a in memory storage for SPA, cookie storage with sesion features for non SPA.Don't use it if not supported and to check support just call this function
It seems that Safari 11 changes the behavior, and now local storage works in a private browser window. Hooray!
Our web app that used to fail in Safari private browsing now works flawlessly. It always worked fine in Chrome's private browsing mode, which has always allowed writing to local storage.
This is documented in Apple's Safari Technology Preview release notes - and the WebKit release notes - for release 29, which was in May 2017.
Specifically:
Apparently this is by design. When Safari (OS X or iOS) is in private browsing mode, it appears as though
localStorage
is available, but trying to callsetItem
throws an exception.What happens is that the window object still exposes
localStorage
in the global namespace, but when you callsetItem
, this exception is thrown. Any calls toremoveItem
are ignored.I believe the simplest fix (although I haven't tested this cross browser yet) would be to alter the function
isLocalStorageNameSupported()
to test that you can also set some value.https://github.com/marcuswestin/store.js/issues/42