Hacker News new | ask | show | jobs
by roywashere 730 days ago
They definitely clear localstorage. But they also are honest about doing this under disk pressure — can’t find the link right now though. My old company had a Cordova app and we stored the client token in localstorage and we found some 16G phones losing their tokens and it turned out to be this. We changed to store tokens in the keyring. From a real web app you can’t but I guess if you would use a cookie this might just work.
1 comments

Also sometimes localStorage gets cleared because it can easily become corrupted from concurrent writes. I had a userscript that made a few fetch calls whenever I visited a certain domain and saved the results in localStorage. Every week or so, all the data in localStorage would just get wiped. Switching to IndexedDB (via localForage) solved the problem.
I was about to say "concurrent writes shouldn't be a problem because localStorage is synchronous and JS is single-threaded," but then I started thinking about multiple tabs, WebWorkers, and multi-process browsers and figured I should double-check the spec.

> Warning! The localStorage getter provides access to shared state. This specification does not define the interaction with other agent clusters in a multiprocess user agent, and authors are encouraged to assume that there is no locking mechanism. A site could, for instance, try to read the value of a key, increment its value, then write it back out, using the new value as a unique identifier for the session; if the site does this twice in two different browser windows at the same time, it might end up using the same "unique" identifier for both sessions, with potentially disastrous effects.

https://html.spec.whatwg.org/multipage/webstorage.html#intro...