localStorage icon indicating copy to clipboard operation
localStorage copied to clipboard

localStorage polyfill doesn't work on Safari private browsing (window.localStorage cannot be overwritten)

Open christopherliu opened this issue 10 years ago • 10 comments

Safari private browsing disables localStorage but also makes window.localStorage readonly, inconveniently. What's the best workaround for this?

christopherliu avatar Jul 02 '15 14:07 christopherliu

I will take a look at the problem one of the next days. But for now:

As I recall, when using safe browsing, a try catch around the "setItem" and "getItem" will catch an error. In such situations one could fallback to using one of the other solutions, such as the FlashStorage.

mortzdk avatar Jul 03 '15 21:07 mortzdk

I ran the tests in incognito mode in the newest versions of Firefox, Chrome and Opera and no problems seems to occur there. I'll try to get access to a Windows machine to tests the Safari private browsing.

mortzdk avatar Jul 24 '15 10:07 mortzdk

Yeah AFAIK this is a specifically Safari problem. I have notes on it somewhere but the jist of it is that each of the browsers handles private sessions differently and that Safari's (decidedly un-private) method is to make localStorage available but readonly.

A Googling turned this up: https://blog.whatwg.org/this-week-in-html-5-episode-30

christopherliu avatar Aug 21 '15 22:08 christopherliu

Sorry to revamp an old issue, but what @christopherliu is saying is that you cannot overwrite localStorage when Safari is in private mode.

https://github.com/mortzdk/localStorage/blob/master/dist/localStorage.js#L694

Any plans on working around this?

mradzinski avatar May 23 '16 20:05 mradzinski

I will take a look at the problem, but I must postpone the matter till after the 21. of June, since I'm in the process of writing my Master's Thesis.

mortzdk avatar May 25 '16 06:05 mortzdk

Was passing exactly through this problem and found a module that deals using this technique: https://raw.githubusercontent.com/ripeworks/local-storage-fallback/master/src/hasStorage.js

gabrielfurini avatar Apr 28 '17 19:04 gabrielfurini

The same technique I use in version 3.0, which is on its way :)

mortzdk avatar Apr 30 '17 10:04 mortzdk

Hi @mortzdk , thanks for the good work, Just wondering if version 3.0 is out and/or safari issue in private browsing has been fixed?. Thank you again

eduzol avatar Jun 28 '17 23:06 eduzol

Hi @eduzol, sorry for not making the v3.0 branch public. It is now public as v3.0 i.e. it is not released yet.

Feel free to do some testing :)

mortzdk avatar Jun 29 '17 07:06 mortzdk

@mortzdk Whats the release schedule?

How does localStorage persist information in Incognito mode?

gajus avatar Jul 06 '17 16:07 gajus