Smoother automation with Browserbase Contexts

Contexts persist data across browser sessions.

Demo preview
1
npx create-browser-app --template context
1
uvx create-browser-app --template context

Create contexts with Browserbase

This template shows how to use Browserbase contexts to persist authentication across sessions. Instead of logging in every time, cookies and tokens are saved once and reused, making flows faster and more reliable. It's perfect for automating logins, accessing gated content, and keeping state consistent across retries or scheduled jobs.

Steps

  1. Create a Browserbase session and log in to a target site using Stagehand.
  2. Save the session's context (including cookies, storage, and tokens).
  3. Reuse the stored context in new sessions without needing to log in again.
  4. Run subsequent scripts faster with authentication and state already in place.