agent-browser Session Management: Auth Persistence & State Reuse

Chrome Profile reuse, Session Name auto-save/restore, State export/import with AES-256-GCM encryption — zero re-login automation.

16Yun Engineering TeamMay 7, 20262 min read

The Problem: Re-login Every Run

The most common pain point in browser automation is login state management. Every script run means re-entering credentials and handling 2FA.

agent-browser offers multiple solutions:

SolutionConfigBest ForPersists
Chrome Profile--profile <name>Reuse existing Chrome loginCookies, localStorage, IndexedDB, Service Workers
Persistent Profile--profile <path>Custom state directoryFull browser state
Session Name--session-name <name>Lightweight stateCookies + localStorage
State File--state <path>Explicit import/exportAuth snapshot

Option 1: Chrome Profile Reuse (Zero Config)

If you're already logged into a site in Chrome, reuse that state directly:

# List available Chrome profiles
agent-browser profiles

# Reuse Default profile's login state
agent-browser --profile Default open https://example.com

# Use a named profile
agent-browser --profile "Work" open https://app.example.com

Import from Running Chrome

# 1. Launch Chrome with remote debugging
# macOS:
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --remote-debugging-port=9222

# 2. Connect and save state
agent-browser --auto-connect state save ./my-auth.json

# 3. Use saved state
agent-browser --state ./my-auth.json open https://app.example.com/dashboard

Option 2: Session Name Auto Management

# First run — state auto-saved after login
agent-browser --session-name mysite open https://example.com/login
# Login manually...

# Subsequent runs — cookies and localStorage auto-restored
agent-browser --session-name mysite open https://example.com/dashboard
# Already logged in!

State files stored in ~/.agent-browser/sessions/, auto-expire after 30 days.

Session Isolation

agent-browser --session-name site-a open https://example.com
agent-browser --session-name site-b open https://example.com

# Via env variable
export AGENT_BROWSER_SESSION_NAME=mysite
agent-browser open https://example.com

Session Encryption

openssl rand -hex 32
export AGENT_BROWSER_ENCRYPTION_KEY=your-64-char-hex-key

# State files encrypted with AES-256-GCM automatically
agent-browser --session-name secure-site open https://example.com
VariableDescription
AGENT_BROWSER_SESSION_NAMEAuto-save/restore session name
AGENT_BROWSER_ENCRYPTION_KEYAES-256-GCM key (64-char hex)
AGENT_BROWSER_STATE_EXPIRE_DAYSState expiry in days (default 30)

Option 3: Explicit State Management

# Save state
agent-browser state save ./project-auth.json

# Show state summary
agent-browser state show ./project-auth.json

# List all state files
agent-browser state list

# Load state
agent-browser --state ./project-auth.json open https://example.com

# Clean old states
agent-browser state clean --older-than 7

Proxy + Session Binding

For long-running accounts, bind 16Yun Dedicated Proxy with session:

export HTTP_PROXY=http://user:pass@dedicated.16yun.cn:8888
export AGENT_BROWSER_SESSION_NAME=shop-manager

# First: login
agent-browser open https://seller.example.com/login

# Later: auto-restored
agent-browser open https://seller.example.com/dashboard

Multi-Account Isolation

HTTP_PROXY=http://user:pass@dedicated-a.16yun.cn:8888 \
  agent-browser --session-name shop-01 open https://seller.example.com

HTTP_PROXY=http://user:pass@dedicated-b.16yun.cn:8888 \
  agent-browser --session-name shop-02 open https://seller.example.com

Security Notes

  • State files contain plaintext session tokens unless encrypted
  • Always set AGENT_BROWSER_ENCRYPTION_KEY in production
  • Add state files to .gitignore
  • Restrict dedicated proxy whitelists to your scraping servers only

Summary

SolutionOne-LinerComplexity
--profile <name>Reuse Chrome loginZero config
--session-name <name>Auto save/restoreLow
--state <path>Explicit import/exportMedium
Encryption + proxyProduction-grade securityMedium

Need an enterprise proxy plan?

We can tailor architecture to your target domains, concurrency, and reliability goals.