From ea5a0bd5f0a89166a7166b61e11aebbfeb2b366d Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Fri, 31 Oct 2025 18:12:30 +0530 Subject: [PATCH] fix: Add Web Crypto feature detection for BotID in React Native WebView (#24790) * fix: Add Web Crypto feature detection for BotID in React Native WebView Fixes #24360 - Add feature detection to check for window.crypto availability before initializing BotID - Skip BotID initialization in React Native WebView environments - Prevents 'undefined is not an object (evaluating crypto)' error during booking - BotID requires Web Crypto API which is not available in React Native WebView Co-Authored-By: hariom@cal.com * refactor: Use minimal feature detection for BotID initialization - Remove React Native WebView-specific check - Use pure feature detection for Web Crypto API - Check for window.crypto.getRandomValues availability - Add SSR guard with typeof window check This approach is more robust and environment-agnostic, working across all environments that lack Web Crypto support, not just React Native. Co-Authored-By: hariom@cal.com --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- apps/web/instrumentation-client.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/web/instrumentation-client.ts b/apps/web/instrumentation-client.ts index c233ab6613..dfc63ad88b 100644 --- a/apps/web/instrumentation-client.ts +++ b/apps/web/instrumentation-client.ts @@ -50,7 +50,11 @@ export function onRouterTransitionStart(url: string, navigationType: "push" | "r } } -process.env.NEXT_PUBLIC_VERCEL_USE_BOTID_IN_BOOKER === "1" && +if ( + process.env.NEXT_PUBLIC_VERCEL_USE_BOTID_IN_BOOKER === "1" && + typeof window !== "undefined" && + typeof window.crypto?.getRandomValues === "function" +) { initBotId({ protect: [ { @@ -59,3 +63,4 @@ process.env.NEXT_PUBLIC_VERCEL_USE_BOTID_IN_BOOKER === "1" && }, ], }); +}