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
chrome://version → “Profile Path”).
Profile Directory Structure
Profiles use Playwright’slaunchPersistentContext 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:
Multiple Profiles
Use different profile paths for different projects or accounts to keep their browser state isolated:Headless Mode with Profiles
Profiles work in both headed and headless mode:Profiles vs Session State
agent-browser provides two ways to persist state:| Feature | Profiles (--profile) | Session State (--session-name) |
|---|---|---|
| Storage location | Custom directory | ~/.agent-browser/sessions/ |
| What’s stored | Full browser profile | Cookies + localStorage only |
| Encryption | No | Yes (with AGENT_BROWSER_ENCRYPTION_KEY) |
| Browser lifecycle | Persistent context | Regular context with state injection |
| Use case | Full browser state | Lightweight auth persistence |
- You need full browser state (IndexedDB, service workers, cache)
- You want complete isolation between projects
- You’re running long-lived browser sessions
- 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:src/browser.ts:1204-1218 for the complete compatibility checks.
Extensions Support
Extensions require a persistent context, which is incompatible with user profiles: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:Implementation Details
Profiles use Playwright’slaunchPersistentContext 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:
isPersistentContext flag is set to true, which affects how the browser is closed and how pages are managed throughout the session.