From bdeac28d74abd54b0373663cbd57b7858888280f Mon Sep 17 00:00:00 2001
From: Samuel Newman <mozzius@protonmail.com>
Date: Thu, 13 Jun 2024 23:06:22 +0100
Subject: Try/catch URL parsing of referrer (#4511)

---
 src/lib/statsig/statsig.tsx | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

(limited to 'src/lib/statsig/statsig.tsx')

diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx
index d57f1c0aa..f6aed999f 100644
--- a/src/lib/statsig/statsig.tsx
+++ b/src/lib/statsig/statsig.tsx
@@ -43,12 +43,19 @@ if (isWeb && typeof window !== 'undefined') {
   refUrl = decodeURIComponent(params.get('ref_url') ?? '')
 }
 
-if (isWeb && typeof document !== 'undefined' && document != null) {
-  const url = new URL(document.referrer)
-  if (url.hostname !== 'bsky.app') {
-    referrer = document.referrer
-    referrerHostname = url.hostname
-  }
+if (
+  isWeb &&
+  typeof document !== 'undefined' &&
+  document != null &&
+  document.referrer
+) {
+  try {
+    const url = new URL(document.referrer)
+    if (url.hostname !== 'bsky.app') {
+      referrer = document.referrer
+      referrerHostname = url.hostname
+    }
+  } catch {}
 }
 
 export type {LogEvents}
-- 
cgit 1.4.1

