File tree Expand file tree Collapse file tree 4 files changed +34
-14
lines changed Expand file tree Collapse file tree 4 files changed +34
-14
lines changed Original file line number Diff line number Diff line change 11# Unreleased changes
22
3+ * [ #1993 ] ( https://github.com/mozilla/glean.js/pull/1993 ) : Add try-catch around uses of sessionStorage and localStorage in core.
4+
35[ Full changelog] ( https://github.com/mozilla/glean.js/compare/v5.0.4...main )
46
57# v5.0.4 (2025-04-02)
Original file line number Diff line number Diff line change @@ -47,16 +47,20 @@ const setDebugOptionInSessionStorage = (
4747) => {
4848 const key = `Glean.${ option . toString ( ) } ` ;
4949
50- switch ( option ) {
51- case DebugOption . DebugTag :
52- sessionStorage . setItem ( key , value as string ) ;
53- break ;
54- case DebugOption . LogPings :
55- sessionStorage . setItem ( key , ( value as boolean ) . toString ( ) ) ;
56- break ;
57- case DebugOption . SourceTags :
58- sessionStorage . setItem ( key , ( value as string [ ] ) . join ( "," ) ) ;
59- break ;
50+ try {
51+ switch ( option ) {
52+ case DebugOption . DebugTag :
53+ sessionStorage . setItem ( key , value as string ) ;
54+ break ;
55+ case DebugOption . LogPings :
56+ sessionStorage . setItem ( key , ( value as boolean ) . toString ( ) ) ;
57+ break ;
58+ case DebugOption . SourceTags :
59+ sessionStorage . setItem ( key , ( value as string [ ] ) . join ( "," ) ) ;
60+ break ;
61+ }
62+ } catch ( e ) {
63+ console . warn ( e ) ;
6064 }
6165} ;
6266
@@ -69,7 +73,12 @@ const setDebugOptionInSessionStorage = (
6973const getDebugOptionFromSessionStorage = (
7074 option : DebugOptionValue
7175) : string | undefined => {
72- return sessionStorage . getItem ( `Glean.${ option . toString ( ) } ` ) || undefined ;
76+ try {
77+ return sessionStorage . getItem ( `Glean.${ option . toString ( ) } ` ) || undefined ;
78+ } catch ( e ) {
79+ console . warn ( e ) ;
80+ return undefined ;
81+ }
7382} ;
7483
7584namespace Glean {
Original file line number Diff line number Diff line change @@ -209,8 +209,12 @@ export class CoreMetrics {
209209 this . generateNewSession ( ) ;
210210 }
211211
212- // Update the last-active timestamp in LocalStorage to the current time.
213- localStorage . setItem ( "glean_session_last_active" , Date . now ( ) . toString ( ) ) ;
212+ try {
213+ // Update the last-active timestamp in LocalStorage to the current time.
214+ localStorage . setItem ( "glean_session_last_active" , Date . now ( ) . toString ( ) ) ;
215+ } catch ( e ) {
216+ console . warn ( e ) ;
217+ }
214218 }
215219
216220 /**
Original file line number Diff line number Diff line change 99 * @returns {boolean } If the current session is inactive.
1010 */
1111export function isSessionInactive ( sessionLengthInMinutes = 30 ) : boolean {
12- const lastActive = localStorage . getItem ( "glean_session_last_active" ) ;
12+ let lastActive : string | null = null ;
13+ try {
14+ lastActive = localStorage . getItem ( "glean_session_last_active" ) ;
15+ } catch ( e ) {
16+ console . warn ( e ) ;
17+ }
1318 const lastActiveDate = new Date ( Number ( lastActive ) ) ;
1419
1520 // Subtract the session length from the current date.
You can’t perform that action at this time.
0 commit comments