iPad localStorage bug – test your apps!

June 21st, 2010
,

Updating Flickr Clock Photoframe for iPad, I discovered a bug in the way iPad handles localStorage. Searching around on the internet, it seems others have found the bug too.

On the iPad, sometimes – but not always – setting an item will fail:

var teststring = 'abc';
localStorage.setItem('testing', teststring);

or

var teststring = 'abc';
localStorage.testing = teststring;

What’s most annoying is that sometimes setting an item fails and sometimes it succeeds, and when it does fail, it just fails silently, stopping the current function. It can’t even be detected in a try/catch – so it isn’t throwing an error like QUOTA_EXCEEDED_ERR.

The solution is to clear the item first:

var teststring = 'abc';
localStorage.removeItem('testing');
localStorage.setItem('testing', teststring);

or

var teststring = 'abc';
localStorage.removeItem('testing');
localStorage.testing = teststring;

If you have an iPad application that uses Javascript and local storage, you’d better test out your app. It may affect sessionStorage too.

  • Twitter
  • Facebook
  • del.icio.us
  • Digg

One Response to “iPad localStorage bug – test your apps!”

  1. Ronald K says:

    Thanks! I wish I’d found this post before pulling my hair…

Leave a Reply