A session is the fundamental unit of Rammerhead. Every browsing context that flows through the proxy belongs to exactly one session. The session holds the user’s cookies, their localStorage data, an optional per-session upstream proxy, and the character dictionary used for URL shuffling. Understanding sessions is essential before configuring session stores, expiry, or IP restriction.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/binary-person/rammerhead/llms.txt
Use this file to discover all available pages before exploring further.
What a session contains
ARammerheadSession wraps testcafe-hammerhead’s Session class and extends it with persistence data stored in session.data:
data object is what gets serialized to disk or memory. It holds:
| Field | Description |
|---|---|
createdAt | Unix timestamp when the session was created |
lastUsed | Unix timestamp updated on every request |
shuffleDict | The per-session URL shuffling dictionary (null when shuffling is off) |
cookies | The cookie jar, stored as the idx of _cookieJar.store |
externalProxySettings | Upstream HTTP proxy for this session, or null |
injectable | Scripts injected into every proxied page |
restrictIP | IP address that is allowed to use this session |
Session lifecycle
Create a session
The client calls The session ID is what the client embeds in all subsequent proxy URLs.
GET /newsession. Rammerhead generates a unique ID, creates a RammerheadSession, stamps session.data.restrictIP with the caller’s IP, and immediately persists the empty session to the store.Use the session
Every proxied request looks up the session by ID. The store updates
session.lastUsed on each retrieval so the expiry clock resets with activity.Edit the session (optional)
Use
GET /editsession to attach an upstream proxy or toggle URL shuffling without recreating the session:Session expires
The session store periodically sweeps for sessions that have exceeded their inactivity timeout or maximum lifetime and deletes them. The exact thresholds depend on which store you use.
Cookies
Rammerhead mirrors the proxied site’s cookies into the session’s cookie jar (session.cookies). The jar is backed by _cookieJar.store.idx, which is wired into session.data via a property hook:
localStorage sync
Unlike cookies, localStorage is managed by the browser’s JavaScript engine and is not visible to the proxy at the network layer. Rammerhead solves this by injectingrammerhead.js into every proxied page, which intercepts localStorage reads and writes and syncs them to the server via the /syncLocalStorage endpoint.
The sync uses a timestamp-based conflict resolution strategy: when two clients have diverging localStorage state, the version with the higher timestamp wins. This allows a session to be shared across browser tabs or devices without silent data loss.
localStorage sync can be disabled globally by setting
disableLocalStorageSync: true in src/config.js. This is useful if clients send very large localStorage payloads that would cause excessive memory use on the server.IP restriction
WhenrestrictSessionToIP is true in src/config.js, the IP that called /newsession is recorded in session.data.restrictIP. The proxy rejects any subsequent request for that session that comes from a different IP.
External proxy per session
Each session can route its outbound traffic through a separate upstream HTTP proxy, set via/editsession?httpProxy=. This is stored in session.externalProxySettings and passed directly to testcafe-hammerhead’s request pipeline:
httpProxy parameter (or an empty value) clears the upstream proxy and routes traffic directly.
Session stores
Rammerhead ships two session store implementations. Both extendRammerheadSessionAbstractStore.
- RammerheadSessionFileCache (default)
- RammerheadSessionMemoryStore
Sessions are serialized to JSON files in a configurable directory (When to use: production deployments where sessions must survive server restarts.
.rhfsession extension). Active sessions are held in a memory cache; inactive ones are flushed to disk after a timeout and re-loaded on demand.How does session serialization work?
How does session serialization work?
RammerheadSession.serializeSession() produces a JSON string containing the data object (shuffleDict, cookies idx, proxy settings, timestamps) and a separately serialized cookie jar. DeserializeSession(id, json) reconstructs a full RammerheadSession from that string without touching the hook system, then calls connectHammerheadToData(true) to re-attach property hooks with the restored data.What happens if a session file is corrupted?
What happens if a session file is corrupted?
When
deleteCorruptedSessions: true (the default), RammerheadSessionFileCache catches JSON parse errors and automatically deletes the damaged file. The user will need to create a new session. This most often occurs when the Node.js process is killed while writing a session to disk.Can I check whether a session exists without loading it?
Can I check whether a session exists without loading it?
Yes.
GET /sessionexists?id=SESSION_ID returns "exists" or "not found" without touching lastUsed or loading the session into memory.URL shuffling
How per-session URL encoding works and why it matters
JavaScript caching
Disk and memory caches for rewritten JS