Skip to content

Commit

Permalink
fix: browser detection
Browse files Browse the repository at this point in the history
update browser detection logic:
detect either window or web worker (WorkerGlobalScope).

fixes firebase#8299 firebase#8284
  • Loading branch information
JoseVSeb authored Jun 13, 2024
1 parent a90255a commit 2617a23
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/util/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 2617a23

Please sign in to comment.