Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
JoseVSeb committed Jun 13, 2024
1 parent a90255a commit 5f7c0d0
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilly-moons-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/util': patch
---

fix: browser detection (detect either window or web worker)
1 change: 1 addition & 0 deletions config/tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
"lib": [
"es5",
"dom",
"WebWorker",
"es2015.promise",
"es2015.symbol",
"es2015.iterable",
12 changes: 11 additions & 1 deletion packages/util/src/environment.ts
Original file line number Diff line number Diff line change
@@ -77,7 +77,17 @@ 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
);
}

/**

0 comments on commit 5f7c0d0

Please sign in to comment.