-
Notifications
You must be signed in to change notification settings - Fork 8
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
Accessing localStorage
throws error in CookieStore
#9
Comments
…Node Internally in `jsdom` has a getter function defined for `localStorage` that can in some circumstances throw a runtime error that is not handled by the package The code has changed to use a function to qeury whether `localStorage` is available in the runtime context. If accessing `localStorage` global throws an error it returns an error otherwise `true` fixes mswjs#9
Hey, @weyert. Thanks for reporting this. Could you please share a reproduction repository? The error you get is caused by jsdom being corrupted. Evaluating the next line fails in jsdom: idlUtils.implForWrapper(this._document)._origin === "null" Which causes the said exception. That's not something this library or you should be doing directly, so before we address this we need to take a closer look at it. While this is rather an edge case, there are scenarios when accessing |
The same error happens in incognito when third-party cookies are blocked and used inside iframe with different origin. Do you consider merging PR? |
@sAs59, |
…Node Internally in `jsdom` has a getter function defined for `localStorage` that can in some circumstances throw a runtime error that is not handled by the package The code has changed to use a function to qeury whether `localStorage` is available in the runtime context. If accessing `localStorage` global throws an error it returns an error otherwise `true` fixes mswjs#9
* fix: cover the case were accessing `localStorage` can throw error in Node Internally in `jsdom` has a getter function defined for `localStorage` that can in some circumstances throw a runtime error that is not handled by the package The code has changed to use a function to qeury whether `localStorage` is available in the runtime context. If accessing `localStorage` global throws an error it returns an error otherwise `true` fixes #9 * fix(localStorage): merge tests when localStorage is undefined * chore(CookieStore): change function name to "supportsLocalStorage" Co-authored-by: Weyert de Boer <weyert.deboer@tapico.io> Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
🎉 This issue has been resolved in version 0.1.7 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
@mswjs/cookies@0.1.6
for the project I'm working on.The problem is that when using
jsdom
together withnode-fetch
in Next.js can in some occasions throw an error because it tries to accessorigin
. I am getting the following error thrownCannot read properties of null (reading '_origin')
:Looks like it's related to trying to access
localStorage
when running in thejsdom
environment; it expects thedocument.origin
to exist which isn't the case when running server-side, the following line is problematic:https://github.com/jsdom/jsdom/blob/e46f76f7e311447213a3a3be1526db3d53028ee5/lib/jsdom/browser/Window.js#L417-L425
Here is the diff that solved my problem:
This issue body was partially generated by patch-package.
The text was updated successfully, but these errors were encountered: