From 89f9c97ac2dd6a52464fcac1565e5c985de6c427 Mon Sep 17 00:00:00 2001 From: WenruiUte Date: Thu, 12 Mar 2026 11:09:58 +0800 Subject: [PATCH] fix: use correct Browserbase API to release sessions (#707) Browserbase has no DELETE endpoint for sessions. The correct API is POST /v1/sessions/:id with body { status: "REQUEST_RELEASE" }. The old DELETE call returned an error that was silently swallowed, causing every session to leak until the 30-min idle timeout. Fixed in both Node.js (src/browser.ts) and native Rust (cli/src/native/providers.rs) paths. Co-authored-by: Claude Opus 4.6 --- cli/src/native/providers.rs | 4 +++- src/browser.ts | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cli/src/native/providers.rs b/cli/src/native/providers.rs index 797b52d..077764f 100644 --- a/cli/src/native/providers.rs +++ b/cli/src/native/providers.rs @@ -35,11 +35,13 @@ pub async fn close_provider_session(session: &ProviderSession) { "browserbase" => { if let Ok(api_key) = env::var("BROWSERBASE_API_KEY") { let _ = client - .delete(format!( + .post(format!( "https://api.browserbase.com/v1/sessions/{}", session.session_id )) + .header("Content-Type", "application/json") .header("X-BB-API-Key", &api_key) + .json(&serde_json::json!({ "status": "REQUEST_RELEASE" })) .send() .await; } diff --git a/src/browser.ts b/src/browser.ts index 584d886..15078ec 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -862,12 +862,18 @@ export class BrowserManager { * Close a Browserbase session via API */ private async closeBrowserbaseSession(sessionId: string, apiKey: string): Promise { - await fetch(`https://api.browserbase.com/v1/sessions/${sessionId}`, { - method: 'DELETE', + const response = await fetch(`https://api.browserbase.com/v1/sessions/${sessionId}`, { + method: 'POST', headers: { + 'Content-Type': 'application/json', 'X-BB-API-Key': apiKey, }, + body: JSON.stringify({ status: 'REQUEST_RELEASE' }), }); + + if (!response.ok) { + throw new Error(`Failed to close Browserbase session: ${response.statusText}`); + } } /**