QUOTA_EXCEEDED_ERR in Mobile Safari

By  on  

I've been working on an HTML5 application for the new Mozilla Marketplace, writing a tutorial along the way to help all of you create and promote your HTML5 web-powered app.  The HTML5 app uses localStorage to save basic search history, as well as other newer APIs.  While testing my application on my iPhone, I was seeing the following error:

localStorage.setItem("history", JSON.stringify(myObject));

The error caused my app to break, refreshing the page and rendering the app useless!  After a bit of research, I found that the reason for the error was that my Mobile Safari's Private Browsing was turned on.  You'd expect a silent error when this mode is one, but nope -- simply a bricked app.  Since there's no way to detect if the user's browser is in "Private Browsing" is turned on (feature detection still works), the best solution is to wrap localStorage setters in try {} / catch() {} blocks:

try {
	localStorage.setItem("history", JSON.stringify(myObject));
}
catch(e) {}

I'm not seeing a better solution at the moment.  Since there's now way to track Private Mode, and certain interactions break in this mode, using try {} / catch() {} blocks appears to be the best solution.

Recent Features

Incredible Demos

  • By
    MooTools Image Preloading with Progress Bar

    The idea of image preloading has been around since the dawn of the internet. When we didn't have all the fancy stuff we use now, we were forced to use ugly mouseover images to show dynamism. I don't think you were declared an official...

  • By
    Create a Trailing Mouse Cursor Effect Using MooTools

    Remember the old days of DHTML and effects that were an achievement to create but had absolutely no value? Well, a trailing mouse cursor script is sorta like that. And I'm sorta the type of guy that creates effects just because I can.

Discussion

  1. Your site hit the nail on the head. I discovered the best VPN for Gaming at this site http://www.anonymousvpnsoftware.com

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!