'Mobile safari local storage doesn't appear on simulator
I'm running an iPhone simulator, pointing safari there to html/js in the file system, like
file:///Users/me/Desktop/.... The app runs fine, except I'm finding it impossible to use localStorage. The following has the following effect:
html includes js, and js says:
alert('test'); ---> alert appears: test
alert(window); ---> alert appears: [Object object]
alert(Object.keys(window).filter(k => k === 'localStorage')) ---> alert appears: localStorage
But the next alert doesn't even appear, nor does the one following it.
alert(window.localStorage); ---> No alert appears
alert('did we make it here?'); ---> No alert appears
I've googled a bunch and found issues relating to localStorage expiring, and localStorage not working in iframes, but my problem is that it seems to be undefined (worse than undefined, even mentioning localStorage gets the app lost).
EDIT I setup a server and found that the problem is not present when the app is served, rather than read from the file system. This can be a work-around, but I'd still like to understand what's wrong using the file system and how I could possibly debug both ways.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
