Skip to content

Commit

Permalink
fix(replay): Better session storage check (#8547)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mydea committed Jul 17, 2023
1 parent c2b1bfd commit 6444b34
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/replay/src/util/hasSessionStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@ import { WINDOW } from '../constants';

/** If sessionStorage is available. */
export function hasSessionStorage(): boolean {
return 'sessionStorage' in WINDOW && !!WINDOW.sessionStorage;
try {
// This can throw, e.g. when being accessed in a sandboxed iframe
return 'sessionStorage' in WINDOW && !!WINDOW.sessionStorage;
} catch {
return false;
}
}

0 comments on commit 6444b34

Please sign in to comment.