Architecture
Sessions follow a three-level hierarchy:Visual diagram
userId vs sessionKey
userId (Context level)
Purpose: Isolates users from each other. Each userId gets a dedicated browser context. Isolation:- Separate cookies
- Separate localStorage/sessionStorage
- Separate browsing history
- Separate cache
- Different end users in a multi-tenant system
- Different accounts (personal vs work)
- A/B testing with separate profiles
sessionKey (Tab group level)
Purpose: Organizes tabs within a user’s context by task/conversation/workflow. Isolation:- Shares cookies with other tab groups in the same userId
- Logical grouping only (not security boundary)
- Allows bulk tab operations (close all tabs in a task)
listItemId. Both names are accepted for backward compatibility.
From server.js:834-836:
- Grouping tabs by conversation thread
- Organizing research tasks
- Batch closing related tabs
Key distinction: userId isolates cookies, sessionKey organizes tabs. Use userId for security, sessionKey for organization.
Cookie and storage isolation
Per-user cookies
Each userId gets its own cookie jar:Cookie import (authenticated browsing)
From server.js:102-108:- Requires Bearer token matching
CAMOFOX_API_KEY - Max 500 cookies per request
- Only allows: name, value, domain, path, expires, httpOnly, secure, sameSite
- Strips unknown fields
Session timeout
From server.js:176:How timeout works
- lastAccess tracking: Every API call updates
session.lastAccess = Date.now() - Cleanup interval: Every 60 seconds, server checks for stale sessions
- Auto-close: Sessions idle for 30+ minutes are closed and removed
Resource limits
From server.js:176-180:Limits enforcement
Max sessions:- When limit reached, Camofox recycles the oldest tab instead of rejecting
- Oldest = tab with lowest
toolCallscounter
Tab recycling ensures automation never fails due to tab limits - the oldest idle tab is reused transparently.
Session cleanup endpoints
Close single tab
- Closes page
- Removes from tab group
- Cleans up tab lock
- If group becomes empty, deletes group
Close tab group
Close entire user session
- Closes browser context (all tabs + cookies)
- Removes session from memory
- If last session, triggers browser idle shutdown timer
Browser lifecycle
Lazy launch
Browser launches only when first tab is created:Idle shutdown
From server.js:301-317:- When last session closes, start 5-minute countdown
- If new session created, cancel countdown
- After 5 minutes of zero sessions, close browser to free resources
Health recovery
From server.js:344-367:- 3+ consecutive navigation failures
- Browser becomes disconnected
- Critical internal error
Concurrency control
From server.js:232-264:- Max 3 operations per userId can run simultaneously
- Excess operations queue for up to 30 seconds
- After 30s, returns error: “User concurrency limit reached, try again”