ngneat / elf

🧙‍♀️ A Reactive Store with Magical Powers

Home Page:https://ngneat.github.io/elf/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

leon opened this issue · comments

Which @ngneat/elf-* package(s) are the source of the bug?

persist-state

Is this a regression?

No

Description

When you open a chrome incognito tab and have an iframe that uses elf, I get the error

Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

This is because of some security feature of chrome.

This means that my whole app breaks.

to fix this we need to not only check that localStorage is available on the window, but also to wrap it in a try catch, since as soon as we try to access window.localStorage it will throw this error.

https://github.com/ngneat/elf/blob/master/packages/persist-state/src/lib/storage.ts#L37

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.


### Please provide the environment you discovered this bug in

```true
MacOS Chrome 104

Anything else?

No response

Do you want to create a pull request?

Yes