File tree Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Expand file tree Collapse file tree 2 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 11# Unreleased changes
22
3+ * [ #1977 ] ( https://github.com/mozilla/glean.js/pull/1977 ) : Add try-catch around window.sessionStorage access to prevent uncaught error upon ` import ` .
4+
35[ Full changelog] ( https://github.com/mozilla/glean.js/compare/v5.0.3...main )
46
57# v5.0.3 (2024-08-02)
Original file line number Diff line number Diff line change @@ -533,10 +533,19 @@ declare global {
533533}
534534
535535// Only set `Glean` values whenever running inside of a browser.
536- if (
537- typeof window !== "undefined" &&
538- typeof window . sessionStorage !== "undefined"
539- ) {
536+ // When cookies/localStorage/sessionStorage are disabled (at least in Firefox
537+ // and Chrome), an access attempt on the window.sessionStorage property will
538+ // throw an error ("The operation is insecure." in Firefox).
539+ // So try-catch is needed here.
540+ let hasStorage = false ;
541+ try {
542+ hasStorage = typeof window !== "undefined" &&
543+ typeof window . sessionStorage !== "undefined" ;
544+ } catch ( e ) {
545+ console . error ( "No session storage available" , e ) ;
546+ }
547+
548+ if ( hasStorage ) {
540549 window . Glean = {
541550 setLogPings : ( flag : boolean ) => {
542551 setDebugOptionInSessionStorage ( DebugOption . LogPings , flag ) ;
You can’t perform that action at this time.
0 commit comments