Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When chosen storage method isn't available, how can we capture the error? #249

Open
1beb opened this issue Dec 28, 2021 · 1 comment
Open

Comments

@1beb
Copy link

1beb commented Dec 28, 2021

I'm using vuex-persist with localStorage. If localStorage isn't available for some reason (blocked by browser), how can I capture it and show an alert or message? I'd like to be able to warn my users about the need for cookies, but I can't find a good place to hook this in.

If I disable cookies in the browser:

Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document
@Marcel-Sass
Copy link

Marcel-Sass commented Feb 22, 2023

i have the same problem. @1beb did you find a workaround?

Edit:
i have created this quickfix

function getStorage(){
    let test = 'test';
    try {
        window.localStorage.setItem(test, test);
        window.localStorage.removeItem(test);
        return window.localStorage;
    } catch(e) {
        alert('error!');
        return window.localStorage;
    }
}
const vuexLocalStorage = new VuexPersistence({
    key: 'example-vuex',
    storage: getStorage(),
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants