question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Safari Private browsing mode appears to support localStorage, but doesn't

See original GitHub issue

Apparently this is by design. When Safari (OS X or iOS) is in private browsing mode, it appears as though localStorage is available, but trying to call .setItem throws an exception.

store.js line 73 “QUOTA_EXCEEDED_ERR: DOM Exception 22: An attempt was made to add something to storage that exceeded the quota.”

What happens is that the window object still exposes localStorage in the global namespace, but when you call setItem, this exception is thrown. Any calls to .removeItem are ignored.

I believe the simplest fix (although I haven’t tested this cross browser yet) would be to alter the function isLocalStorageNameSupported() to test that you can also set some value.

currently:

function isLocalStorageNameSupported() {
    try { return (localStorageName in win && win[localStorageName]) }
        catch(err) { return false }
}

proposed:

function isLocalStorageNameSupported() {
    try { 
        var supported = (localStorageName in win && win[localStorageName]);
        if (supported) { localStorage.setItem("storage", ""); localStorage.removeItem("storage");
        return supported;
    }
    catch(err) { return false }
}

Of course it’s kind of silly to call this every time you want to check that storage is supported, so you could memoize it, but you get the idea.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
marcuswestincommented, Sep 27, 2013

So I just ran the tests in safari private mode, and store.disabled == true as expected.

Before you rely on any storage, you need to check that it is enabled and working. store.disabled & store.enabled does this for you. Just check one of those flags. If storage isn’t enabled and your product depends on it, you need to notify your user that they must enable storage in order to use your product.

Closing this again as I don’t see anything wrong.

Cheers! Marcus

1reaction
marcuswestincommented, Mar 30, 2012

Yeah 😃

There is no good alternative. Either persistance is possible or it is not. I don’t think there’s anything the library can do that’s better than simply letting you know that persistance is disabled.

BTW: If you feel up for helping the next guy out, I’d really appreciate it if you contributed a note in the README file about store.disabled and issued a pull request. The flag should very much be documented!

Cheers! Marcus

Read more comments on GitHub >

github_iconTop Results From Across the Web

On a browser, sessionStorage in Safari's Private Browsing ...
On Safari on Mac, click "Safari -> Private Browsing" on the menu bar; On Chrome, use "File -> New Incognito Window"; On Firefox,...
Read more >
Safari Private Browsing and localS… | Apple Developer Forums
Hi,. Our html5 application want to access and writes in the local storage while browsing in private mode. We get the following error:...
Read more >
Why Doesn't Missive Work in Safari's Private Browsing Mode?
Safari doesn't allow data to be written in localStorage while in private browsing mode. Among other things, Missive uses localStorage to store your...
Read more >
Quota Exceeded on Safari Private Browsing with localStorage
Safari Private Browsing confusingly disables localStorage.
Read more >
An Analysis of Private Browsing Modes in Modern Browsers
Chrome and Safari) recently added private browsing modes ... While all major browsers support private browsing, ... At first glance it may seem...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found