localStorage
can get cleared by mobile OSs, especially on iOS, when memory is running low.
I usually create a generic Storage
JS class in my app, so I can abstract away the actual implementation of the storage. It has basic get
and set
functionality. In there you can check whether you are in browser or on device. Not ideal, but at least you can test it.
class Storage {
get() {
if(isCordova) {
// save in SQL
} else {
// save in localStorage
}
}
...
}
Perhaps you could try WebSQL
instead of localStorage
for in browser, as long as it’s just for development? It’s deprecated now, so don’t use it in production, but if you’re just testing in Chrome, it would work.