Skip to main content

Overview

By default, browser state (cookies, localStorage, login sessions) is ephemeral and lost when the browser closes. Use --profile to persist state across browser restarts.

Quick Start

What Gets Stored

The profile directory stores all browser state that would normally be ephemeral:
  • Cookies - Session cookies, authentication tokens
  • localStorage - Client-side key-value storage
  • IndexedDB - Structured client-side databases
  • Service Workers - Background scripts and caches
  • Browser cache - Cached resources (images, scripts, stylesheets)
  • Login sessions - Persistent authentication state
  • Browser preferences - Settings and configurations
This is equivalent to Chrome’s user data directory (chrome://version → “Profile Path”).

Profile Directory Structure

Profiles use Playwright’s launchPersistentContext API (see src/browser.ts:1371-1387). The directory structure follows Chromium’s layout:

Path Expansion

Profile paths support tilde (~) expansion to your home directory:
Relative paths are resolved from the current working directory:

Multiple Profiles

Use different profile paths for different projects or accounts to keep their browser state isolated:
Each profile has completely isolated state - cookies, logins, and storage are never shared between profiles.

Headless Mode with Profiles

Profiles work in both headed and headless mode:

Profiles vs Session State

agent-browser provides two ways to persist state: Use profiles when:
  • You need full browser state (IndexedDB, service workers, cache)
  • You want complete isolation between projects
  • You’re running long-lived browser sessions
Use session state when:
  • You only need cookies and localStorage
  • You want encryption at rest
  • You want automatic state management

Compatibility

Limitations

Profiles have some restrictions due to how Playwright’s persistent contexts work: Cannot use with CDP connections:
Cannot use with storage state files:
See src/browser.ts:1204-1218 for the complete compatibility checks.

Extensions Support

Extensions require a persistent context, which is incompatible with user profiles:
Extensions create their own temporary profile directory automatically (see src/browser.ts:1348-1370).

Security Considerations

Permissions

Profile directories contain sensitive data like cookies and auth tokens. Protect them with appropriate file permissions:

Sharing Profiles

Never commit profile directories to version control or share them between users. Each profile should be user-specific and machine-specific.

Multi-User Systems

On shared systems, use user-specific profile paths to prevent data leakage:

Cleanup

Profile directories can grow large over time due to browser cache. Clean them periodically:

Use Cases

Authenticated Testing

Login once, then reuse the session for all tests:

Development Workflow

Maintain separate profiles for development vs production:

Multi-Account Automation

Run multiple accounts simultaneously using different sessions:
Each session gets its own daemon and browser instance, allowing true parallel execution.

Implementation Details

Profiles use Playwright’s launchPersistentContext API, which launches the browser with a permanent user data directory. This is the same mechanism Chrome uses for user profiles. From src/browser.ts:1371-1387:
The isPersistentContext flag is set to true, which affects how the browser is closed and how pages are managed throughout the session.