Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Local Storage Not Persistent

Site is used on Samsung Galaxy Tab with the Gingerbread OS. Browsers used so far are the stock browser as well as Dolphin HD. Items in local storage seem to at random disappear when users go in and out of network coverage. Storage also seems to not be able to fully survive browser crashes or device restarts. Weird part is storage doesn't usually clear out completely, just a large number of items go missing. Anyone else heard of this problem or have any suggestions?

Edit: By local storage I mean,

localStorage["Key"] = value;

Retrived using:

localStorage.getItem("Key");

In every case, directly after adding to local storage, the site is able to retrieve and use the data. However, sometime after this usually after roaming or browser/tablet crashes, the data is no longer there. Everything I've found says local storage should persist, so I don't really know where to go from here.

like image 916
jmease Avatar asked Nov 09 '11 22:11

jmease


1 Answers

How about debugging this a bit further? Maybe your own code is somehow overwriting it? I am using localStorage/sessionStorage in PhoneGap and never had them disappearing...

Add the following event handler:

window.addEventListener("storage", function(e) {
   console.debug(e);
}, false);

Which will fire (and log to console, on desktop browser) every time the storage is accessed. You could also log more detailed info to be seen in your adb logcat (like the key being accessed!)

Have a look at this stackoverflow question for more details on Storage events.

like image 82
Leon Avatar answered Sep 21 '22 11:09

Leon