From b1ea50534d04e49d74878505b8145ae76ab91bc8 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Fri, 19 Jan 2024 14:59:01 +0100 Subject: [PATCH 1/5] Fix isSafari crashing on React Native --- packages/util/src/environment.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/util/src/environment.ts b/packages/util/src/environment.ts index 04bbd92165d..0f73550c30e 100644 --- a/packages/util/src/environment.ts +++ b/packages/util/src/environment.ts @@ -138,6 +138,7 @@ export function isNodeSdk(): boolean { export function isSafari(): boolean { return ( !isNode() && + navigator.userAgent !== undefined && // not react-native navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome') ); From 52f86b31b579f259d15fd7d313ce43ee92f25d46 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Fri, 19 Jan 2024 14:09:39 +0000 Subject: [PATCH 2/5] Add changeset --- .changeset/purple-cooks-explode.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/purple-cooks-explode.md diff --git a/.changeset/purple-cooks-explode.md b/.changeset/purple-cooks-explode.md new file mode 100644 index 00000000000..7507ae5717a --- /dev/null +++ b/.changeset/purple-cooks-explode.md @@ -0,0 +1,5 @@ +--- +'@firebase/util': patch +--- + +Fix isSafari() throwing on React Native From dad17fc5b4a8789683f0b971361c432a280b41e3 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Fri, 19 Jan 2024 20:59:08 +0100 Subject: [PATCH 3/5] Remove comment --- packages/util/src/environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/util/src/environment.ts b/packages/util/src/environment.ts index 0f73550c30e..7beb40efded 100644 --- a/packages/util/src/environment.ts +++ b/packages/util/src/environment.ts @@ -138,7 +138,7 @@ export function isNodeSdk(): boolean { export function isSafari(): boolean { return ( !isNode() && - navigator.userAgent !== undefined && // not react-native + navigator.userAgent !== undefined && navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome') ); From e38eae55fb28ced02c018d6c9be8b966a28873e9 Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Fri, 19 Jan 2024 21:07:18 +0100 Subject: [PATCH 4/5] Use truthy check --- packages/util/src/environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/util/src/environment.ts b/packages/util/src/environment.ts index 7beb40efded..9e54d228125 100644 --- a/packages/util/src/environment.ts +++ b/packages/util/src/environment.ts @@ -138,7 +138,7 @@ export function isNodeSdk(): boolean { export function isSafari(): boolean { return ( !isNode() && - navigator.userAgent !== undefined && + navigator.userAgent && navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome') ); From d94a69bcef081e684cf5ebe8dcc4054f9966bbea Mon Sep 17 00:00:00 2001 From: Simon Farshid Date: Fri, 19 Jan 2024 21:22:40 +0100 Subject: [PATCH 5/5] use !! to coerce navigator.userAgent to a boolean Co-authored-by: dconeybe --- packages/util/src/environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/util/src/environment.ts b/packages/util/src/environment.ts index 9e54d228125..f2afaede0f1 100644 --- a/packages/util/src/environment.ts +++ b/packages/util/src/environment.ts @@ -138,7 +138,7 @@ export function isNodeSdk(): boolean { export function isSafari(): boolean { return ( !isNode() && - navigator.userAgent && + !!navigator.userAgent && navigator.userAgent.includes('Safari') && !navigator.userAgent.includes('Chrome') );