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

Replay: Gracefully degrade if sessionStorage isn't available #8392

Closed
bruno-garcia opened this issue Jun 22, 2023 · 10 comments · Fixed by #8394 or #8547
Closed

Replay: Gracefully degrade if sessionStorage isn't available #8392

bruno-garcia opened this issue Jun 22, 2023 · 10 comments · Fixed by #8394 or #8547
Labels
Package: replay Issues related to the Sentry Replay SDK

Comments

@bruno-garcia
Copy link
Member

Reported by a customer that runs their app on several different embedded browsers such as email apps

For example, if an Android embedded browser has settings.setDomStorageEnabled(false), then sessionStorage isn’t available. Sentry checks for this with sessionStorage in window, but it’s possible for that to be true, but window.sessionStorage to be null, resulting in later errors. This would prevent functionality from behaving as normal.

We might need to gate access to sessionStorage and if we can't access this at other spots we need to find a way to gracefully degrade the SDK. If Replay cant' work, we should disable recording, but let the other functionalies of the SDK (e.g: error reporting) continue to function

@bruno-garcia bruno-garcia added the Package: replay Issues related to the Sentry Replay SDK label Jun 22, 2023
mydea added a commit that referenced this issue Jun 23, 2023
It seems in some environments `sessionStorage` my be unset to `null` or similar. To be extra careful, we can guard for existence as well there.

Fixes #8392
mydea added a commit that referenced this issue Jun 23, 2023
It seems in some environments `sessionStorage` my be unset to `null` or
similar. To be extra careful, we can guard for existence as well there.

Fixes #8392
@bruno-garcia
Copy link
Member Author

Wow that was fast! Thanks Francesco!

@mydea
Copy link
Member

mydea commented Jul 12, 2023

@mydea mydea reopened this Jul 12, 2023
@charleskoehl
Copy link

charleskoehl commented Jul 15, 2023

It still happens in our next.js app when it is in an iframe

SecurityError
Failed to read the 'sessionStorage' property from 'Window': Access is denied for this document.
mechanism
instrument
handled
true
function
setTimeout

../../node_modules/@sentry/replay/esm/index.js in hasSessionStorage at line 4394:48
System

  return new EventBufferArray();
}
/** If sessionStorage is available. */
function hasSessionStorage() {
  return 'sessionStorage' in WINDOW && !!WINDOW.sessionStorage;
}
/**
 * Removes the session from Session Storage and unsets session in replay instance
 */
../../node_modules/@sentry/replay/esm/index.js in session at line 4538:1
System

../../node_modules/@sentry/replay/esm/index.js in session at line 4556:1
System

../../node_modules/@sentry/replay/esm/index.js in ReplayContainer._loadAndCheckSession at line 7669:29

@shakiba
Copy link

shakiba commented Jul 17, 2023

I also have this issue when sentry is in a sandboxed iframe.

@mydea
Copy link
Member

mydea commented Jul 17, 2023

I opened a fix to fully solve this here: #8547 - should go out in the next version!

mydea added a commit that referenced this issue Jul 17, 2023
Apparently accessing sessionStorage in an iframe with certain
permissions can result in a throw, so we try-catch this to ensure we do
not produce any errors.

Closes #8392
@shakiba
Copy link

shakiba commented Jul 17, 2023

Awesome, thank you @mydea !

@mydea
Copy link
Member

mydea commented Jul 18, 2023

This is out in 7.59.2 now!

@shakiba
Copy link

shakiba commented Jul 19, 2023

Great, thank you!
I use @sentry/vite-plugin, it depends on 7.53.1, it would be great if you could update the version there as well.

@mydea
Copy link
Member

mydea commented Jul 19, 2023

The vite plugin should use it's own Sentry versions for internal stuff only. Is this interfering with your app somehow?

@shakiba
Copy link

shakiba commented Jul 19, 2023

Sorry, my bad. I just recalled I'm using script tag to add sentry to the page.
It's all good, thanks for fixing the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: replay Issues related to the Sentry Replay SDK
Projects
Archived in project
4 participants