← Blog

BLOG

Remote Browser Data: How to Keep Sessions Alive Across Cloud Workers

Remote browser data: learn how to persist sessions, manage profiles, and keep AI agents alive across cloud workers with hosted Chromium.

August 24, 20269 min readRemote Browser

# Remote Browser Data: How to Keep Sessions Alive Across Cloud Workers

When you run browser automation across multiple cloud workers, the first thing that breaks is remote browser data. A login cookie stored in one worker's memory is gone in the next. A session token captured in a local Chromium profile doesn't transfer to a serverless function. And if you're building an AI agent that needs to browse the web in production, you'll quickly discover that "stateless" is the enemy of "logged in."

This guide explains how remote browser data works in a hosted Chromium runtime, why session persistence matters for AI agents and test suites, and how to keep browser sessions alive across cloud workers without rebuilding your infrastructure.

What Is Remote Browser Data?

Remote browser data refers to the state a browser maintains during and between sessions: cookies, localStorage, IndexedDB, cache, service workers, and profile directories. In a local browser, this data lives on disk. In a remote browser, it lives in a hosted environment—typically a container or VM running Chromium—and is exposed to your code via an API.

The core problem: cloud workers are ephemeral. A Lambda function, a Fly.io machine, or a Kubernetes pod can be recycled at any moment. If your browser session data lives only in that worker's memory, you lose it when the worker dies.

Remote Browser solves this by separating the browser process from your application code. The browser runs in a dedicated hosted session. Your code connects to it via WebSocket (CDP) or HTTP. When a worker dies, the browser session—and all its remote browser data—stays alive.

Why Session Persistence Matters for AI Agents

AI agents are the most demanding consumers of remote browser data. A typical agent workflow looks like this:

  1. Navigate to a site.
  2. Log in with credentials.
  3. Perform a multi-step task (fill forms, click buttons, extract data).
  4. Use the session for follow-up tasks.

If step 2's login cookie vanishes between step 3 and step 4, the agent fails. This is why "how to keep browser sessions alive across multiple cloud workers" is a common search query—it's the difference between a demo and a production system.

With a hosted browser runtime, the session persists independently of your worker. You can connect, disconnect, and reconnect without losing state. This is critical for:

  • Long-running agents that need to maintain context over hours or days.
  • Retry logic that reconnects to a browser after a worker crash.
  • Parallel workers that share a single authenticated session.

The Problem with Local Browser Profiles

Many developers start with a local Playwright or Puppeteer script. They use launchPersistentContext to save a profile to disk. This works on a single machine, but it falls apart in production:

ApproachSession PersistenceMulti-Worker SupportProduction Readiness
Local Chromium + launchPersistentContextYes, on local diskNoLow—requires a dedicated VM
Serverless function + in-memory browserNoNoVery low—state lost on cold start
Docker container + volume mountYes, but complexPartial—requires shared storageMedium—you manage the infrastructure
Hosted Chromium (Remote Browser)Yes, server-sideYes—any worker can connectHigh—infrastructure is managed

The local profile approach also has a hidden cost: you're responsible for keeping that browser patched, secure, and running 24/7. If you're building an AI agent, that's time you're not spending on your actual product.

How Remote Browser Persists Data

Remote Browser runs Chromium in a hosted environment. Each session has a dedicated profile directory that persists across connections. Here's how it works:

  1. You create a session via the API. The session spins up a Chromium instance with a fresh or saved profile.
  2. You connect to the session using Playwright, Puppeteer, or raw CDP.
  3. The browser runs independently of your code. It can navigate, execute JavaScript, and store data.
  4. You disconnect—the browser keeps running. The profile is saved.
  5. You reconnect later, from the same worker or a different one. The session state is intact.

This is fundamentally different from launching a browser inside your worker. The browser is the persistent entity; your code is the transient client.

Connecting to a Remote Browser with Playwright

Here's a concrete example using Playwright to connect to a remote browser session. This assumes you have a session ID from the Remote Browser API.

import { chromium } from 'playwright';

// Connect to an existing remote browser session via CDP
const browser = await chromium.connectOverCDP(
  `wss://remote-browser.dev/cdp/${sessionId}`
);

// The browser context is already there—with cookies, localStorage, etc.
const context = browser.contexts()[0];
const page = await context.newPage();

// This page is part of the same session. If you logged in earlier,
// you're still logged in now.
await page.goto('https://example.com/dashboard');
console.log(await page.title());

// Do work, then disconnect. The session stays alive.
await browser.close();

The key line is connectOverCDP. This uses the Chrome DevTools Protocol to attach to a running browser. You're not launching a new browser; you're joining an existing one. All remote browser data—cookies, localStorage, session tokens—is preserved.

For more details on connecting, see our guide on Playwright remote browser connections.

Keeping Sessions Alive Across Cloud Workers

The most common production pattern is a "connect and release" model. Your worker connects to a session, does work, and disconnects. The session persists. Here's how to structure this:

1. Create a Session Once

Don't create a new session for every task. Create one session per logical workflow (e.g., one per user, one per scraping target). Store the session ID in your database.

2. Connect on Demand

When a worker needs to perform a task, it fetches the session ID and connects via CDP. The connection is lightweight—it's just a WebSocket.

3. Handle Disconnects Gracefully

Your worker might crash. That's fine. The browser session is still running. The next worker can connect and pick up where the last one left off.

4. Use Persistent Profiles for Repeat Logins

If you're automating a site that requires login, save the profile after the first login. Subsequent sessions start already authenticated. This is how you avoid re-entering credentials on every task.

Remote Browser Data vs. Browser Automation APIs

There's a distinction between a "browser automation API" and a "remote browser data runtime." Many tools offer the former: you send a command, get a result, and the browser is destroyed. Remote Browser offers the latter: the browser is a persistent resource with state.

This matters for AI agents because agents need to:

  • Remember what they've done across steps.
  • Maintain authentication state.
  • Recover from errors without starting over.

A stateless API can't do this. A session-based runtime can. If you're evaluating tools, ask: "Can I disconnect and reconnect to the same browser session?" If the answer is no, you'll be rebuilding state on every call.

Production Criteria for Remote Browser Data

When evaluating a remote browser solution for production, check these criteria:

Session Isolation

Each session should be isolated. One session's cookies and storage should not leak into another. This is non-negotiable for security and compliance.

Persistent Profiles

The ability to save and reload profiles is essential. Without it, you're re-authenticating on every session, which is slow and fragile.

Configurable Browser Settings

You may need to adjust browser settings for specific sites: user agents, viewport sizes, geolocation, or proxy settings. Make sure the runtime exposes these as configuration options.

Live Debugging

When something goes wrong, you need to see what the browser is doing. A live viewer or screenshot API is critical for debugging AI agent failures.

Usage Controls

In production, you need to control costs. Session timeouts, idle limits, and concurrency caps prevent runaway spending.

For a deeper dive into these criteria, see our remote browser configuration tool guide.

Common Pitfalls with Remote Browser Data

Pitfall 1: Storing Session IDs in Memory

If you store session IDs in a worker's memory, you lose them when the worker dies. Store them in a database or key-value store.

Pitfall 2: Assuming Cookies Are Enough

Cookies are the most visible part of session state, but not the only part. localStorage and IndexedDB can also hold critical state. Make sure your persistence mechanism captures the entire profile, not just cookies.

Pitfall 3: Reconnecting to a Dead Session

Hosted browsers can crash or be terminated. Always handle connection errors by creating a new session and retrying the task.

Pitfall 4: Sharing Sessions Across Users

Never share a browser session between different users. This is a security risk and can cause data leakage. Use one session per user or per logical workflow.

Remote Browser Data and Browser-Use Workflows

If you're using the browser-use library for AI agents, remote browser data is what makes it work in production. The library connects to a browser, performs actions, and returns results. But if the browser is local and ephemeral, you can't scale.

With a hosted runtime, browser-use can connect to a persistent session. This means:

  • The agent can pause and resume.
  • The agent can be distributed across workers.
  • The agent's state is preserved between runs.

We've covered this in detail in our remote browser for AI agents post.

The Chrome DevTools Protocol Connection

All of this relies on the Chrome DevTools Protocol (CDP). CDP is the standard for browser automation. It's what Playwright, Puppeteer, and Selenium use under the hood. When you connect to a remote browser, you're speaking CDP over WebSocket.

The official Chrome DevTools Protocol documentation is the authoritative reference. Understanding CDP is essential for debugging remote browser data issues. For example, if cookies aren't persisting, you can use CDP's Network.getAllCookies to inspect what the browser actually has.

Conclusion: Treat Remote Browser Data as Infrastructure

The shift from local to remote browser data is the same shift that happened with databases and queues: from "something you manage" to "something you use." A hosted Chromium runtime gives you persistent sessions, reliable state, and the ability to scale across cloud workers without rebuilding your automation stack.

If you're building an AI agent or a browser automation pipeline, stop treating the browser as a disposable resource. Make it a persistent service. Your sessions will survive worker crashes, your agents will maintain context, and your production system will actually work.

For a practical guide on moving from local scripts to a hosted runtime, see our remote web browser post. And if you're ready to start, check the pricing page for current session costs and limits.