Skip to content

Commit 3c9154d

Browse files
waleedlatif1claude
andcommitted
fix(stagehand): preserve liveViewUrl and sessionId on agent error
If the agent throws after Browserbase session init succeeds, callers can still surface the live view / session ID for debugging. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 2d3368f commit 3c9154d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • apps/sim/app/api/tools/stagehand/agent

apps/sim/app/api/tools/stagehand/agent/route.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
169169

170170
const modelName = provider === 'anthropic' ? 'anthropic/claude-sonnet-4-6' : 'openai/gpt-5'
171171

172+
let sessionId: string | null = null
173+
let liveViewUrl: string | null = null
174+
172175
try {
173176
logger.info('Initializing Stagehand with Browserbase (v3)', { provider, modelName })
174177

@@ -191,8 +194,7 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
191194
await stagehand.init()
192195
logger.info('Stagehand initialized successfully')
193196

194-
const sessionId = stagehand.browserbaseSessionID ?? null
195-
let liveViewUrl: string | null = null
197+
sessionId = stagehand.browserbaseSessionID ?? null
196198
if (sessionId) {
197199
try {
198200
const debugResponse = await fetch(
@@ -361,6 +363,8 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
361363
{
362364
error: errorMessage,
363365
details: errorDetails,
366+
liveViewUrl,
367+
sessionId,
364368
},
365369
{ status: 500 }
366370
)

0 commit comments

Comments
 (0)