Skip to content

Conversation

sameelarif
Copy link
Member

No description provided.

Copy link

vercel bot commented Oct 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
priv-gemini-browser Ready Ready Preview Comment Oct 7, 2025 0:10am

miguelg719 and others added 11 commits October 6, 2025 15:33
* update urls, ts ignore fix (#8)

* feat: add query param parsing (#9)

* update urls, ts ignore fix

* added query param parsing to instatiate chatfeed with query params

* disable captcha solving if query params are passed in (#10)

* update gemini model

* update model tag (#12)

* add region routing

* more precise region & probability dist routing

* no inline import

* add dep

---------

Co-authored-by: Kyle Jeong <77771518+Kylejeong2@users.noreply.github.com>
Co-authored-by: Miguel <36487034+miguelg719@users.noreply.github.com>
const prefix = timezone.split("/")[0];
if (prefix in prefixToRegion) {
return prefixToRegion[prefix];
function getRegionFromTimezoneAbbr(timezoneAbbr?: string): BrowserbaseRegion {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The timezone region mapping is completely broken - the client sends timezone identifiers like "America/New_York" but the server now expects timezone abbreviations like "EST". This will cause all sessions to default to "us-west-2" regardless of user location.

View Details
📝 Patch Details
diff --git a/app/api/session/route.ts b/app/api/session/route.ts
index 569427d..7d0c303 100644
--- a/app/api/session/route.ts
+++ b/app/api/session/route.ts
@@ -7,7 +7,84 @@ type BrowserbaseRegion =
   | "eu-central-1"
   | "ap-southeast-1";
 
-// Timezone abbreviation to region mapping
+// IANA timezone identifier to region mapping
+const exactTimezoneMap: Record<string, BrowserbaseRegion> = {
+  // US East Coast
+  "America/New_York": "us-east-1",
+  "America/Detroit": "us-east-1",
+  "America/Kentucky/Louisville": "us-east-1",
+  "America/Kentucky/Monticello": "us-east-1",
+  "America/Indiana/Indianapolis": "us-east-1",
+  "America/Indiana/Vincennes": "us-east-1",
+  "America/Indiana/Winamac": "us-east-1",
+  "America/Indiana/Marengo": "us-east-1",
+  "America/Indiana/Petersburg": "us-east-1",
+  "America/Indiana/Vevay": "us-east-1",
+  "America/Toronto": "us-east-1",
+  "America/Montreal": "us-east-1",
+  "America/Halifax": "us-east-1",
+
+  // US West Coast
+  "America/Los_Angeles": "us-west-2",
+  "America/Vancouver": "us-west-2",
+  "America/Tijuana": "us-west-2",
+
+  // Europe
+  "Europe/London": "eu-central-1",
+  "Europe/Paris": "eu-central-1",
+  "Europe/Berlin": "eu-central-1",
+  "Europe/Rome": "eu-central-1",
+  "Europe/Madrid": "eu-central-1",
+  "Europe/Amsterdam": "eu-central-1",
+  "Europe/Brussels": "eu-central-1",
+  "Europe/Vienna": "eu-central-1",
+  "Europe/Prague": "eu-central-1",
+  "Europe/Warsaw": "eu-central-1",
+  "Europe/Budapest": "eu-central-1",
+  "Europe/Stockholm": "eu-central-1",
+  "Europe/Oslo": "eu-central-1",
+  "Europe/Copenhagen": "eu-central-1",
+  "Europe/Helsinki": "eu-central-1",
+  "Europe/Zurich": "eu-central-1",
+  "Europe/Dublin": "eu-central-1",
+  "Europe/Lisbon": "eu-central-1",
+  "Europe/Athens": "eu-central-1",
+  "Europe/Istanbul": "eu-central-1",
+  "Europe/Moscow": "eu-central-1",
+
+  // Asia-Pacific
+  "Asia/Tokyo": "ap-southeast-1",
+  "Asia/Seoul": "ap-southeast-1",
+  "Asia/Shanghai": "ap-southeast-1",
+  "Asia/Hong_Kong": "ap-southeast-1",
+  "Asia/Singapore": "ap-southeast-1",
+  "Asia/Bangkok": "ap-southeast-1",
+  "Asia/Jakarta": "ap-southeast-1",
+  "Asia/Manila": "ap-southeast-1",
+  "Asia/Kuala_Lumpur": "ap-southeast-1",
+  "Asia/Kolkata": "ap-southeast-1",
+  "Asia/Dubai": "ap-southeast-1",
+  "Australia/Sydney": "ap-southeast-1",
+  "Australia/Melbourne": "ap-southeast-1",
+  "Australia/Brisbane": "ap-southeast-1",
+  "Australia/Perth": "ap-southeast-1",
+  "Australia/Adelaide": "ap-southeast-1",
+  "Pacific/Auckland": "ap-southeast-1",
+};
+
+// Prefix-based region mapping for fallback
+const prefixToRegion: Record<string, BrowserbaseRegion> = {
+  America: "us-west-2",
+  US: "us-west-2",
+  Canada: "us-west-2",
+  Europe: "eu-central-1",
+  Africa: "eu-central-1",
+  Asia: "ap-southeast-1",
+  Australia: "ap-southeast-1",
+  Pacific: "ap-southeast-1",
+};
+
+// Timezone abbreviation to region mapping (for legacy support)
 const timezoneAbbreviationMap: Record<string, BrowserbaseRegion> = {
   // US East Coast
   EST: "us-east-1",
@@ -93,19 +170,52 @@ function selectRegionWithProbability(
   return baseRegion;
 }
 
-function getRegionFromTimezoneAbbr(timezoneAbbr?: string): BrowserbaseRegion {
+function getClosestRegion(timezone?: string): BrowserbaseRegion {
   try {
-    if (!timezoneAbbr) {
+    if (!timezone) {
       return "us-west-2"; // Default if no timezone provided
     }
 
-    // Direct lookup from timezone abbreviation
-    const region = timezoneAbbreviationMap[timezoneAbbr.toUpperCase()];
-    if (region) {
-      return region;
+    // Check exact IANA timezone identifier matches first
+    if (timezone in exactTimezoneMap) {
+      return exactTimezoneMap[timezone];
+    }
+
+    // Check timezone abbreviation matches (legacy support)
+    const abbreviationRegion = timezoneAbbreviationMap[timezone.toUpperCase()];
+    if (abbreviationRegion) {
+      return abbreviationRegion;
+    }
+
+    // Check prefix matches for IANA identifiers
+    const prefix = timezone.split("/")[0];
+    if (prefix in prefixToRegion) {
+      return prefixToRegion[prefix];
+    }
+
+    // Use offset-based fallback for unknown timezones
+    try {
+      const date = new Date();
+      // Create a date formatter for the given timezone
+      const formatter = new Intl.DateTimeFormat("en-US", { timeZone: timezone });
+      // Get the timezone offset by comparing formatted times
+      const utcDate = new Date(date.toISOString().slice(0, -1));
+      const localDate = new Date(formatter.format(date) + " UTC");
+      const hourOffset = (localDate.getTime() - utcDate.getTime()) / (1000 * 60 * 60);
+
+      // Map offset ranges to regions
+      if (hourOffset >= -12 && hourOffset <= -4) {
+        return "us-west-2"; // US West Coast and Pacific
+      } else if (hourOffset >= -3 && hourOffset <= 4) {
+        return "eu-central-1"; // Europe and Africa
+      } else if (hourOffset >= 5 && hourOffset <= 12) {
+        return "ap-southeast-1"; // Asia-Pacific
+      }
+    } catch {
+      // If offset calculation fails, fall through to default
     }
 
-    // Fallback to us-west-2 for unknown abbreviations
+    // Fallback to us-west-2 for unknown timezones
     return "us-west-2";
   } catch {
     return "us-west-2";
@@ -128,12 +238,12 @@ async function createSession(timezone?: string) {
     advancedStealth: true
   };
 
-  // Use timezone abbreviation to determine base region
-  const closestRegion = getRegionFromTimezoneAbbr(timezone);
+  // Use timezone identifier to determine base region
+  const closestRegion = getClosestRegion(timezone);
   // Apply probability routing for potential load balancing
   const finalRegion = selectRegionWithProbability(closestRegion);
 
-  console.log("timezone abbreviation:", timezone);
+  console.log("timezone:", timezone);
   console.log("mapped to region:", closestRegion);
   console.log("final region after probability routing:", finalRegion);
 

Analysis

Timezone region mapping broken for IANA identifiers in session creation

What fails: getRegionFromTimezoneAbbr() only handles timezone abbreviations like "EST" but client sends IANA timezone identifiers like "America/New_York", causing all sessions to default to "us-west-2"

How to reproduce:

// Client sends IANA identifier from browser:
Intl.DateTimeFormat().resolvedOptions().timeZone; // Returns "America/New_York"

// Server function only matches abbreviations:
getRegionFromTimezoneAbbr("America/New_York"); // Returns "us-west-2" (fallback)

Result: All users with IANA timezone identifiers (default browser behavior) get routed to us-west-2 instead of their geographic region

Expected: "America/New_York" should map to "us-east-1", "Europe/London" to "eu-central-1", per Intl.DateTimeFormat docs which return IANA timezone names

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants