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/lemon-eggs-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@browserbasehq/stagehand": patch
---

log Browserbase session status when websocket is closed due to session timeout
31 changes: 31 additions & 0 deletions packages/core/lib/v3/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ export class V3 {
return this.browserbaseDebugUrl;
}
private _onCdpClosed = (why: string) => {
if (this.state.kind === "BROWSERBASE") {
void this._logBrowserbaseSessionStatus();
}

// Single place to react to the transport closing
this._immediateShutdown(`CDP transport closed: ${why}`).catch(() => {});
};
Expand Down Expand Up @@ -1459,6 +1463,33 @@ export class V3 {
throw new StagehandInvalidArgumentError("Unsupported page object.");
}

private async _logBrowserbaseSessionStatus(): Promise<void> {
if (this.state.kind !== "BROWSERBASE") {
return;
}

try {
const snapshot = (await this.state.bb.sessions.retrieve(
this.state.sessionId,
)) as { id?: string; status?: string };
if (!snapshot?.status) return;

const sessionId = snapshot.id ?? this.state.sessionId;
const message =
snapshot.status === "TIMED_OUT"
? `Browserbase session timed out (sessionId: ${sessionId})`
: `Browserbase session status: ${snapshot.status}`;

this.logger({
category: "v3",
message,
level: 0,
});
} catch {
// Ignore failures; nothing to log
}
}

/**
* Create a v3 agent instance (AISDK tool-based) with execute().
* Mirrors the v2 Stagehand.agent() tool mode (no CUA provider here).
Expand Down