Skip to content

Commit 34090f6

Browse files
committed
fix: browser detection
update browser detection logic: detect either window or web worker (WorkerGlobalScope). fixes firebase#8299 firebase#8284
1 parent a90255a commit 34090f6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.changeset/chilly-moons-play.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/util': patch
3+
---
4+
5+
fix: browser detection (detect either window or web worker)

packages/util/src/environment.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,14 @@ export function isNode(): boolean {
7777
* Detect Browser Environment
7878
*/
7979
export function isBrowser(): boolean {
80-
return typeof self === 'object' && self.self === self;
80+
return typeof window !== 'undefined' || isWebWorker();
81+
}
82+
83+
/**
84+
* Detect Web Worker context
85+
*/
86+
export function isWebWorker(): boolean {
87+
return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
8188
}
8289

8390
/**

0 commit comments

Comments
 (0)