-
Notifications
You must be signed in to change notification settings - Fork 34
Add try-catch around window.sessionStorage access
#1977
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
Add try-catch around window.sessionStorage access
#1977
Conversation
glean/src/core/glean.ts
Outdated
| try { | ||
| if ( | ||
| typeof window !== "undefined" && | ||
| typeof window.sessionStorage !== "undefined" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of wrapping the whole block in try-catch, what about something like:
let hasStorage = false;
try {
hasStorage = typeof window !== "undefined"
&& typeof window.sessionStorage !== "undefined";
} catch (e) {
console.error("No session storage available", e)
}
if (hasStorage) {
// ...This would not increase indentation and would reduce the scope of the try block.
8223601 to
6a83ada
Compare
|
Updated the patch based on @Dexterp37's suggestion. Thank you, @Dexterp37 |
Dexterp37
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chenba do you need a release cut ? Is this blocking something or was this problem found by some other investigation?
I do need a release. That error is blocking https://accounts.firefox.com/cookies_disabled from being rendered if the user disabled cookies/session storage/local storage in their browser preferences. |
Got it. @chenba would you kindly add a changelog entry ? I'll make sure to cut a release tomorrow morning. |
6a83ada to
4f2487f
Compare
|
Updated patch to include an entry in the changelog under "Unreleased changes". |
Thanks. I merged this, but now I'm also wondering if this would lead to other problems if the generated metrics are ever called (or if windows.Glean.* stuff) is ever called. @chenba I'm ok with cutting a release for this, but have you tested it? Does it solve your problem or do we need more changes? |
|
Thanks, @Dexterp37.
I did test it. And it solves our issue, which is that the error is thrown at
I'm not familiar with this code base but it looks like the |
Ok, cutting a release |
Pull Request checklist
glean/folder, run:npm run testRuns all testsnpm run lintRuns all lintersCHANGELOG.mdor an explanation of why it does not need one