localstorage and Safari Private Browsing

556 views
Skip to first unread message

Ryan Kruse

unread,
Mar 13, 2014, 6:30:25 PM3/13/14
to angula...@googlegroups.com
Safari in Private mode advertises window.localStorage but it throws an exception when you try to save to it.

QuotaExceededError: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.

Is there a graceful way to handle this in the angularCacheFactory? 

Jason Dobry

unread,
Mar 13, 2014, 6:53:00 PM3/13/14
to angula...@googlegroups.com
angularCacheFactory could be improved to be a little smarter at figuring out if localStorage is supported. Something like this:

function isLocalStorageNameSupported() 
{
    var testKey = 'test', storage = window.sessionStorage;
    try 
    {
        storage.setItem(testKey, '1');
        storage.removeItem(testKey);
        return localStorageName in win && win[localStorageName];
    } 
    catch (error) 
    {
        return false;
    }
}

Ryan Kruse

unread,
Mar 13, 2014, 8:22:15 PM3/13/14
to angula...@googlegroups.com
OK, I'll handle it outside the library for now then. Thanks for the response Jason.
Reply all
Reply to author
Forward
0 new messages