MCPcopy
hub / github.com/browserbase/mcp-server-browserbase / cleanupSession

Method cleanupSession

src/sessionManager.ts:418–444  ·  view source on GitHub ↗

* Clean up a session by closing the browser and removing it from tracking. * This method handles both closing Stagehand and cleanup, and is idempotent. * * @param sessionId The session ID to clean up

(sessionId: string)

Source from the content-addressed store, hash-verified

416 * @param sessionId The session ID to clean up
417 */
418 async cleanupSession(sessionId: string): Promise<void> {
419 process.stderr.write(
420 `[SessionManager] Cleaning up session: ${sessionId}\n`,
421 );
422
423 // Get the session to close it gracefully
424 const session = this.browsers.get(sessionId);
425 if (session) {
426 await this.closeBrowserGracefully(session, sessionId);
427 }
428
429 // Remove from browsers map
430 this.browsers.delete(sessionId);
431
432 // Clear default session reference if this was the default
433 if (sessionId === this.defaultSessionId && this.defaultBrowserSession) {
434 this.defaultBrowserSession = null;
435 }
436
437 // Reset active session to default if this was the active one
438 if (this.activeSessionId === sessionId) {
439 process.stderr.write(
440 `[SessionManager] Cleaned up active session ${sessionId}, resetting to default.\n`,
441 );
442 this.setActiveSessionId(this.defaultSessionId);
443 }
444 }
445
446 // Function to close all managed browser sessions gracefully
447 async closeAllSessions(): Promise<void> {

Callers 1

actionFunction · 0.80

Calls 2

setActiveSessionIdMethod · 0.95

Tested by

no test coverage detected