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 <noreply@anthropic.com>
This commit is contained in:
WenruiUte
2026-03-11 22:09:58 -05:00
committed by GitHub
co-authored by Claude Opus 4.6
parent db3d23d496
commit 89f9c97ac2
2 changed files with 11 additions and 3 deletions
+3 -1
View File
@@ -35,11 +35,13 @@ pub async fn close_provider_session(session: &ProviderSession) {
"browserbase" => { "browserbase" => {
if let Ok(api_key) = env::var("BROWSERBASE_API_KEY") { if let Ok(api_key) = env::var("BROWSERBASE_API_KEY") {
let _ = client let _ = client
.delete(format!( .post(format!(
"https://api.browserbase.com/v1/sessions/{}", "https://api.browserbase.com/v1/sessions/{}",
session.session_id session.session_id
)) ))
.header("Content-Type", "application/json")
.header("X-BB-API-Key", &api_key) .header("X-BB-API-Key", &api_key)
.json(&serde_json::json!({ "status": "REQUEST_RELEASE" }))
.send() .send()
.await; .await;
} }
+8 -2
View File
@@ -862,12 +862,18 @@ export class BrowserManager {
* Close a Browserbase session via API * Close a Browserbase session via API
*/ */
private async closeBrowserbaseSession(sessionId: string, apiKey: string): Promise<void> { private async closeBrowserbaseSession(sessionId: string, apiKey: string): Promise<void> {
await fetch(`https://api.browserbase.com/v1/sessions/${sessionId}`, { const response = await fetch(`https://api.browserbase.com/v1/sessions/${sessionId}`, {
method: 'DELETE', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json',
'X-BB-API-Key': apiKey, 'X-BB-API-Key': apiKey,
}, },
body: JSON.stringify({ status: 'REQUEST_RELEASE' }),
}); });
if (!response.ok) {
throw new Error(`Failed to close Browserbase session: ${response.statusText}`);
}
} }
/** /**