Skip to main content

Stopping a Session

Always stop sessions when your automation completes to avoid unnecessary billing.
const result = await client.browser.session.stop({
  sessionId: "sess_abc123xyz",
});

console.log(result);

Session Lifecycle

1

Create

Call create() to start a new browser session. The session becomes active immediately.
2

Active

Session is running and consuming billing time. Connect via CDP to automate the browser.
3

Stop

Call stop() when finished, or the session auto-stops after 1 hour of inactivity.
4

Stopped

Session ends. Logs are retained temporarily before cleanup.
Always explicitly stop sessions when done to avoid unnecessary billing from the 1-hour timeout.

Cleanup Best Practices

async function withSession<T>(
  fn: (session: Session) => Promise<T>
): Promise<T> {
  const session = await client.browser.session.create();

  try {
    return await fn(session);
  } finally {
    await client.browser.session.stop({ sessionId: session.sessionId });
  }
}

// Usage
await withSession(async (session) => {
  const browser = await chromium.connectOverCDP(session.cdpUrl);
  // ... automation
  await browser.close();
});

Next Steps