Scrapeless Wiki

What Is a Browser Session? – Definition and How It Works

Informational P2 what is a browser session

Learn what a browser session holds, how contexts isolate state, why session continuity matters for automation, and how sessions are persisted.

A browser session is the accumulated state of a browsing context: cookies, storage, cache, and the server-side state those artefacts reference. It is what makes a sequence of requests feel like one continuous visit.

1. What a Session Holds

Store Contains Lifetime
Cookies Server-set state, including authentication Per cookie attributes
Local storage Key-value data set by the page Until cleared
Session storage Per-tab data Until the tab closes
IndexedDB Structured client-side data Until cleared
Cache Fetched resources Per caching headers
Service worker state Registered handlers and their caches Until unregistered

Authentication usually lives in cookies; application state increasingly lives in the storage APIs.

2. Contexts Provide Isolation

Modern automation libraries expose browser contexts: independent state containers inside one browser process. Each has its own cookies and storage, and none can see the others.

This is how many independent sessions run efficiently β€” one browser process, many contexts, rather than many browser processes.

3. Why Continuity Matters in Automation

Any flow spanning more than one request depends on session state.

  • Logins persist only while the cookies are returned.
  • Consent dialogs are satisfied by a cookie; discard it and the banner reappears every visit.
  • Challenge clearance is typically recorded as a cookie, so dropping it means being re-tested.
  • Multi-step forms rely on server-side state keyed to the session.

A client that discards state between requests repeats every one of those steps and looks less consistent while doing so.

4. Sessions and Egress

Server-side state is often associated with the address that created it. Changing egress mid-session invalidates that association, producing sudden logouts and empty results.

The clean unit is one task, one session, one exit address, for the task's whole duration.

5. Persisting and Reusing

State can be exported and restored, which avoids repeating an expensive login for every run.

Two cautions: stored session state is credential-equivalent and must be protected accordingly, and it expires β€” a restored session that silently no longer authenticates produces results that look like a content change rather than an auth failure.

6. Isolation as a Design Requirement

Separate tasks need separate contexts. Sharing one leaks cookies and storage between them, which mixes identities, breaks per-task assumptions, and makes failures difficult to reproduce.

7. Cleaning Up

Contexts hold memory and open resources. Close them explicitly when a task finishes rather than relying on process exit; long-running collectors that leave contexts open are the usual cause of gradual memory growth.

8. Summary

A browser session is the cookies, storage, and cached state that make consecutive requests one continuous visit, isolated per context in modern automation libraries.

Preserve it within a task, keep one exit address for its duration, isolate tasks from one another, protect exported state as a credential, and close contexts when done.