angular-2-local-storage icon indicating copy to clipboard operation
angular-2-local-storage copied to clipboard

not working in private mode of safari in iphone

Open gowthamrodda opened this issue 8 years ago • 3 comments

This module is working fine in chrome, safari of desktop. but I tested my application in iphone safari , localstorage values are not retrieved. any solution for this?

gowthamrodda avatar Jan 04 '17 11:01 gowthamrodda

Unfortunately this is unrelated to this library, and is just how Safari on iOS works - by design. LocalStorage appears to be available, but the quota is set to 0 in private mode. If you google for "Safari iOS localStorage private mode" you'll find a bunch of info about the issue.

We could detect this scenario by doing:

let isEnabled = true;
try {
    localStorage.setItem('test', 'test');
} catch (e) {
    isEnabled = false;
}

However, I'm not sure what the fallback storage ought to be.

I'm falling back to storing values in memory for one application - e.g. if LS fails I put my session token in a global variable on window and grab it from there when I need it. That works for my situation, but it might be unexpected if we built it in to this library (obviously the data is gone from memory as soon as you refresh the page).

Any suggestions on dealing with this are welcome

elwynelwyn avatar Jan 04 '17 12:01 elwynelwyn

@elwynelwyn I think the correct way is to fallback to a cookie. That's what I'm doing in my projects and I've also seen others to it like that. It's a simple fix as well.

chrillewoodz avatar Aug 18 '17 06:08 chrillewoodz

Using cookies as a fallback seems like a decent workaround to build in to your app.

I'd be hesitant to make that a default fallback that silently happens though due to 1) cookie size limitations in some browsers 2) unexpected csrf implications if your data is suddenly being automatically sent to the server on every request as a cookie

elwynelwyn avatar Aug 18 '17 07:08 elwynelwyn