File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @firebase/util ' : patch
3
+ ---
4
+
5
+ fix: browser detection (detect either window or web worker)
Original file line number Diff line number Diff line change 18
18
import { CONSTANTS } from './constants' ;
19
19
import { getDefaults } from './defaults' ;
20
20
21
+ /**
22
+ * Type placeholder for `WorkerGlobalScope` from `webworker`
23
+ */
24
+ declare class WorkerGlobalScope { }
25
+
21
26
/**
22
27
* Returns navigator.userAgent string or '' if it's not defined.
23
28
* @return user agent string
@@ -77,7 +82,18 @@ export function isNode(): boolean {
77
82
* Detect Browser Environment
78
83
*/
79
84
export function isBrowser ( ) : boolean {
80
- return typeof self === 'object' && self . self === self ;
85
+ return typeof window !== 'undefined' || isWebWorker ( ) ;
86
+ }
87
+
88
+ /**
89
+ * Detect Web Worker context
90
+ */
91
+ export function isWebWorker ( ) : boolean {
92
+ return (
93
+ typeof WorkerGlobalScope !== 'undefined' &&
94
+ typeof self !== 'undefined' &&
95
+ self instanceof WorkerGlobalScope
96
+ ) ;
81
97
}
82
98
83
99
/**
You can’t perform that action at this time.
0 commit comments