> For the complete documentation index, see [llms.txt](https://developers.oxylabs.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.oxylabs.io/products/headless-browser/persistent-sessions-and-profiles.md).

# Persistent Sessions & Profiles

Managing long-running multi-stage automation workflows or maintaining logged-in user states across distinct connection sequences requires persisting browser states. Oxylabs Headless Browser offers two advanced persistence systems:

<table data-header-hidden><thead><tr><th width="178"></th><th></th></tr></thead><tbody><tr><td><a href="#persistent-sessions-sticky-sessions"><strong>Persistent Sessions</strong></a></td><td>Keep a live remote browser environment running across client disconnections.</td></tr><tr><td><a href="#persistent-profiles"><strong>Persistent Profiles</strong></a></td><td>Save and restore cookies, local storage, and browser cache. <em>(Activation required)</em></td></tr></tbody></table>

## Persistent Sessions

Persistent (sticky) Sessions keep your remote browser instance running in the cloud (even when your local automation script disconnects) by defining a custom `session_name` to your connection URL:

```bash
wss://USER:PASS@ubc.oxylabs.io?session_name=checkout-flow-test
```

<table><thead><tr><th width="127">Parameter</th><th width="534">Description</th><th width="98">Type</th></tr></thead><tbody><tr><td><code>session_name</code></td><td>When defined, a sessions persist up to the maximum time-to-live (TTL) (max 24h or until stopped). Reconnect with the same <code>session_name</code> to reattach the same session ID and existing tabs. Supported format: <code>^[A-Za-z0-9-]{3,36}$</code></td><td>String</td></tr><tr><td><code>keep_alive</code></td><td>While <code>true</code> (default), the session stays on in the cloud after you disconnect (up to max TTL – 24h).<br>While <code>false</code>, calling <code>browser.close()</code> reclaims and closes the session.</td><td>Boolean</td></tr></tbody></table>

### Reconnect to an existing tab

```javascript
// Reconnect to existing session with 
const browser = await chromium.connectOverCDP(endpoint);
const ctx = browser.contexts()[0];
const page = ctx.pages().find(p => p.url().includes("http://example.com "));
```

## Persistent Profiles

{% hint style="warning" %}
**Persistent Profiles** feature and `o_profile` parameters are restricted by default. To access them, contact Oxylabs support ([live chat](https://oxylabs.io/) or [email](mailto:support@oxylabs.io)) or your Dedicated Account Manager.
{% endhint %}

Save cookies and localStorage under a named profile and restore them in a brand-new session. Using the following parameters lets you maintain a logged-in persona across sessions without re-authenticating every time:

<table><thead><tr><th width="191">Parameter</th><th width="456">Description</th><th width="102">Type</th></tr></thead><tbody><tr><td><code>o_profile</code></td><td>Save/restore cookies and localStorage with a named profile (14 days from last use). Supported format: <code>^[A-Za-z0-9_-]{1,36}$</code></td><td>String</td></tr><tr><td><code>o_profile_save</code></td><td>Force profile save mid-session. Default: <code>true</code>.</td><td>Boolean</td></tr><tr><td><code>proxy_resi_ses_id</code></td><td>Custom session ID to pin residential exit IP across sessions. Supported format: <code>^[A-Za-z0-9]{3,36}$</code>.</td><td>String</td></tr><tr><td><code>proxy_resi_ses_time</code></td><td>Duration to hold the pinned residential proxy exit IP in minutes. Min <code>1</code>, max <code>1440</code> (24h).</td><td>Integer</td></tr></tbody></table>

{% hint style="info" %}
The number of profiles per account is capped (`max_profiles`). Exceeding the limit returns `CDP_LIMIT_REACHED: profile limit reached` error. Reuse one stable profile name when possible, or contact Oxylabs support ([live chat](https://oxylabs.io/) or [email](mailto:support@oxylabs.io)) or your Dedicated Account Manager to raise the limit.
{% endhint %}

### Reliable cross-session restore <a href="#reliable-cross-session-restore" id="reliable-cross-session-restore"></a>

For websites with strict bot monitoring systems, saving cookies is not enough. If a restored profile connects from a different residential exit IP, your cookies may get invalidated, resulting in blank pages or security verification screens.

To ensure consistent logins, pair your profile with a pinned residential exit IP:

```javascript
// Session 1: Authenticate and back up state
const connectionOne = "wss://USER:PASS@ubc.oxylabs.io?o_profile=my_user_profile&proxy_resi_ses_id=ip_session_abc&proxy_resi_ses_time=120";

// Session 2: Restore profile with the exact same IP session context
const connectionTwo = "wss://USER:PASS@ubc.oxylabs.io?o_profile=my_user_profile&proxy_resi_ses_id=ip_session_abc&proxy_resi_ses_time=120";
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers.oxylabs.io/products/headless-browser/persistent-sessions-and-profiles.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
