File tree 2 files changed +13
-2
lines changed
2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change 2
2
* A utility class for safely interacting with localStorage.
3
3
*/
4
4
export class LocalStorage {
5
- static store : Storage | undefined = globalThis . localStorage ;
5
+ static store : Storage | undefined = ensureLocalStorage ( ) ;
6
6
7
7
/**
8
8
* Safely get a value from localStorage.
@@ -51,3 +51,14 @@ export class LocalStorage {
51
51
this . store ?. removeItem ( key ) ;
52
52
}
53
53
}
54
+
55
+ function ensureLocalStorage ( ) : Storage | undefined {
56
+ try {
57
+ const testKey = "__test_localStorage__" ;
58
+ globalThis . localStorage . setItem ( testKey , testKey ) ;
59
+ globalThis . localStorage . removeItem ( testKey ) ;
60
+ return globalThis . localStorage ;
61
+ } catch {
62
+ return undefined ;
63
+ }
64
+ }
Original file line number Diff line number Diff line change 95
95
"bundlesize" : [
96
96
{
97
97
"path" : " ./dist/search-insights.min.js" ,
98
- "maxSize" : " 3.60 kB"
98
+ "maxSize" : " 3.70 kB"
99
99
}
100
100
],
101
101
"packageManager" :
" [email protected] "
You can’t perform that action at this time.
0 commit comments