Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/flat-avocados-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": minor
---

rename browserbaseResumeSessionID -> browserbaseSessionID
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ This constructor is used to create an instance of Stagehand.
- `apiKey`: (optional) your Browserbase API key. Defaults to `BROWSERBASE_API_KEY` environment variable.
- `projectId`: (optional) your Browserbase project ID. Defaults to `BROWSERBASE_PROJECT_ID` environment variable.
- `browserbaseSessionCreateParams`: configuration options for creating new Browserbase sessions.
- `browserbaseResumeSessionID`: ID of an existing Browserbase session to resume.
- `browserbaseSessionID`: ID of an existing live Browserbase session. Overrides `browserbaseSessionCreateParams`.
- `logger`: a function that handles log messages. Useful for custom logging implementations.
- `verbose`: an `integer` that enables several levels of logging during automation:
- `0`: limited to no logging
Expand Down Expand Up @@ -174,7 +174,7 @@ This constructor is used to create an instance of Stagehand.
// Resume existing Browserbase session
const stagehand = new Stagehand({
env: "BROWSERBASE",
browserbaseResumeSessionID: "existing-session-id",
browserbaseSessionID: "existing-session-id",
});
```

Expand Down
2 changes: 1 addition & 1 deletion examples/stagehand.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const StagehandConfig: ConstructorParams = {
projectId: process.env.BROWSERBASE_PROJECT_ID!,
},
enableCaching: true /* Enable caching functionality */,
browserbaseResumeSessionID:
browserbaseSessionID:
undefined /* Session ID for resuming Browserbase sessions */,
modelName: "gpt-4o" /* Name of the model to use */,
modelClientOptions: {
Expand Down
24 changes: 11 additions & 13 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function getBrowser(
headless: boolean = false,
logger: (message: LogLine) => void,
browserbaseSessionCreateParams?: Browserbase.Sessions.SessionCreateParams,
browserbaseResumeSessionID?: string,
browserbaseSessionID?: string,
): Promise<BrowserResult> {
if (env === "BROWSERBASE") {
if (!apiKey) {
Expand Down Expand Up @@ -83,20 +83,19 @@ async function getBrowser(
apiKey,
});

if (browserbaseResumeSessionID) {
if (browserbaseSessionID) {
// Validate the session status
try {
const sessionStatus = await browserbase.sessions.retrieve(
browserbaseResumeSessionID,
);
const sessionStatus =
await browserbase.sessions.retrieve(browserbaseSessionID);

if (sessionStatus.status !== "RUNNING") {
throw new Error(
`Session ${browserbaseResumeSessionID} is not running (status: ${sessionStatus.status})`,
`Session ${browserbaseSessionID} is not running (status: ${sessionStatus.status})`,
);
}

sessionId = browserbaseResumeSessionID;
sessionId = browserbaseSessionID;
const browserbaseDomain =
BROWSERBASE_REGION_DOMAIN[sessionStatus.region] ||
"wss://connect.browserbase.com";
Expand Down Expand Up @@ -173,7 +172,7 @@ async function getBrowser(

logger({
category: "init",
message: browserbaseResumeSessionID
message: browserbaseSessionID
? "browserbase session resumed"
: "browserbase session started",
level: 0,
Expand Down Expand Up @@ -321,7 +320,6 @@ export class Stagehand {
private browserbaseSessionCreateParams?: Browserbase.Sessions.SessionCreateParams;
private enableCaching: boolean;
private variables: { [key: string]: unknown };
private browserbaseResumeSessionID?: string;
private contextPath?: string;

private actHandler?: StagehandActHandler;
Expand All @@ -341,7 +339,7 @@ export class Stagehand {
browserbaseSessionCreateParams,
domSettleTimeoutMs,
enableCaching,
browserbaseResumeSessionID,
browserbaseSessionID,
modelName,
modelClientOptions,
}: ConstructorParams = {
Expand All @@ -367,7 +365,7 @@ export class Stagehand {
this.domSettleTimeoutMs = domSettleTimeoutMs ?? 30_000;
this.headless = headless ?? false;
this.browserbaseSessionCreateParams = browserbaseSessionCreateParams;
this.browserbaseResumeSessionID = browserbaseResumeSessionID;
this.browserbaseSessionID = browserbaseSessionID;
}

async init(
Expand All @@ -387,7 +385,7 @@ export class Stagehand {
this.headless,
this.logger,
this.browserbaseSessionCreateParams,
this.browserbaseResumeSessionID,
this.browserbaseSessionID,
).catch((e) => {
console.error("Error in init:", e);
const br: BrowserResult = {
Expand Down Expand Up @@ -469,7 +467,7 @@ export class Stagehand {
page,
}: InitFromPageOptions): Promise<InitFromPageResult> {
console.warn(
"initFromPage is deprecated and will be removed in the next major version. To instantiate from a page, use `browserbaseResumeSessionID` in the constructor.",
"initFromPage is deprecated and will be removed in the next major version. To instantiate from a page, use `browserbaseSessionID` in the constructor.",
);
this.page = page;
this.context = page.context();
Expand Down
2 changes: 1 addition & 1 deletion types/stagehand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface ConstructorParams {
domSettleTimeoutMs?: number;
browserbaseSessionCreateParams?: Browserbase.Sessions.SessionCreateParams;
enableCaching?: boolean;
browserbaseResumeSessionID?: string;
browserbaseSessionID?: string;
modelName?: AvailableModel;
modelClientOptions?: ClientOptions;
}
Expand Down
Loading