Git Product home page Git Product logo

Comments (10)

marcuswestin avatar marcuswestin commented on May 22, 2024 1

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

from store.js.

marcuswestin avatar marcuswestin commented on May 22, 2024 1

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

from store.js.

marcuswestin avatar marcuswestin commented on May 22, 2024

Hi @tjarratt, thanks for the report!

You can (and should) check store.disabled. If persistance is not possible and you require it, you should probably display a message saying that the user needs to switch browser or exit private mode. if (store.disabled) { alert('error: storage is disabled') }

The check for store.disabled is currently on https://github.com/marcuswestin/store.js/blob/master/store.js#L188.

I think I prefer the current implementation since whether the browser supports localStorage or not is a different issue from whether persistance using localStorage is possible on the current webpage. localStorage may be supported but temporarily disabled.

Let me know if that addresses your issue, and feel free to close the issue if it does.

Cheers!
Marcus

from store.js.

tjarratt avatar tjarratt commented on May 22, 2024

Ah, I should have known there would have been some clever "is this working" boolean exposed. Well thanks for pointing that out.

It's a little frustrating that anyone that uses this needs to make that check, but it does keep the implementation cleaner from that perspective.

from store.js.

tkaravou avatar tkaravou commented on May 22, 2024

Still having this issue on Safari desktop + iOS in private mode. This worked for me:

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;
      }
    }

from store.js.

marcuswestin avatar marcuswestin commented on May 22, 2024

Great! Wanna pull request?

from store.js.

marcuswestin avatar marcuswestin commented on May 22, 2024

Why are you using storage = window.sessionStorage instead of window.localStorage?

from store.js.

marcuswestin avatar marcuswestin commented on May 22, 2024

Also, shouldn't this case be covered by the store.disabled flag testing starting on line

try {
?

from store.js.

marcuswestin avatar marcuswestin commented on May 22, 2024

Store.js v2.0 has been released with support for Safari private mode.

If you update to the latest version using the v1 backcompatible build you will automatically get this functionality plus a bunch more :)

from store.js.

sighWang avatar sighWang commented on May 22, 2024

@marcuswestin thank you for update. Which commit support this feature?

from store.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.