From 34bcaff04d032cf70639ffc4f23c1a91654619b9 Mon Sep 17 00:00:00 2001 From: Pete Gautier Date: Mon, 2 Dec 2024 11:07:02 -0800 Subject: [PATCH] fix: check for undefined userAgent string before calling includes() --- .../client-sdk-web/src/internal/client-metadata-provider.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/client-sdk-web/src/internal/client-metadata-provider.ts b/packages/client-sdk-web/src/internal/client-metadata-provider.ts index 3f812255e..9d314d21f 100644 --- a/packages/client-sdk-web/src/internal/client-metadata-provider.ts +++ b/packages/client-sdk-web/src/internal/client-metadata-provider.ts @@ -51,8 +51,11 @@ export class ClientMetadataProvider { // Each browser uses its own JS engine, the best we can do is detect the browser name. // Source: https://developer.mozilla.org/en-US/docs/Web/API/Window/navigator function getBrowserName(userAgent: string): string { + // Check for empty string, null, or undefined. + if (!userAgent) { + return 'unknown-browser'; + } // The order matters here, and this may report false positives for unlisted browsers. - if (userAgent.includes('Firefox')) { // "Mozilla/5.0 (X11; Linux i686; rv:104.0) Gecko/20100101 Firefox/104.0" return 'Mozilla-Firefox';