diff --git a/.changeset/chilly-moons-play.md b/.changeset/chilly-moons-play.md new file mode 100644 index 00000000000..1d1db3c15c6 --- /dev/null +++ b/.changeset/chilly-moons-play.md @@ -0,0 +1,5 @@ +--- +'@firebase/util': patch +--- + +fix: browser detection (detect either window or web worker) diff --git a/packages/util/src/environment.ts b/packages/util/src/environment.ts index f2afaede0f1..9c2024232d4 100644 --- a/packages/util/src/environment.ts +++ b/packages/util/src/environment.ts @@ -77,7 +77,14 @@ export function isNode(): boolean { * Detect Browser Environment */ export function isBrowser(): boolean { - return typeof self === 'object' && self.self === self; + return typeof window !== 'undefined' || isWebWorker(); +} + +/** + * Detect Web Worker context + */ +export function isWebWorker(): boolean { + return typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope; } /**