Skip to content

Commit

Permalink
Enable Multi-Region Support for Sessions (#287) (#288)
Browse files Browse the repository at this point in the history
* Use use correct domain (#287)

* spelling

---------

Co-authored-by: Makoto Tanji <[email protected]>
  • Loading branch information
kamath and tan-z-tan authored Dec 9, 2024
1 parent 9605836 commit 5afa0b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/green-avocados-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

add multi-region support for browserbase
11 changes: 10 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import { logLineToString } from "./utils";
dotenv.config({ path: ".env" });

const DEFAULT_MODEL_NAME = "gpt-4o";
const BROWSERBASE_REGION_DOMAIN = {
"us-west-2": "wss://connect.usw2.browserbase.com",
"us-east-1": "wss://connect.use1.browserbase.com",
"eu-central-1": "wss://connect.euc1.browserbase.com",
"ap-southeast-1": "wss://connect.apse1.browserbase.com",
};

async function getBrowser(
apiKey: string | undefined,
Expand Down Expand Up @@ -91,7 +97,10 @@ async function getBrowser(
}

sessionId = browserbaseResumeSessionID;
connectUrl = `wss://connect.browserbase.com?apiKey=${apiKey}&sessionId=${sessionId}`;
const browserbaseDomain =
BROWSERBASE_REGION_DOMAIN[sessionStatus.region] ||
"wss://connect.browserbase.com";
connectUrl = `${browserbaseDomain}?apiKey=${apiKey}&sessionId=${sessionId}`;

logger({
category: "init",
Expand Down

0 comments on commit 5afa0b9

Please sign in to comment.