October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

How to Reconnect to a Browser Session with an API

Reconnect with a provider-issued endpoint before its timeout, or use a persistent session API when browser state must survive a longer gap or restart.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To reconnect to a remote browser, you need its provider-issued reconnect endpoint, the right authentication, and a connection made before the provider’s timeout expires. Save the endpoint while the original connection is active, then use a compatible client to attach to the still-running browser and inspect its contexts and pages. If the browser may stop or the gap is longer, use a provider session API that preserves state across runs instead; an expired live-browser endpoint cannot revive a terminated process.

Choose the right kind of reconnection

“Reconnect” can mean either attaching again to a browser process that is still running or restoring browser state through a longer-lived session service. Those are different lifecycle models. A generic API cannot reconnect to an arbitrary browser: the host must provide an endpoint for the browser and protocol you intend to use.

As an Amazon Associate I earn from qualifying purchases.

Need Use What must remain available
Brief interruption; resume the same live browser A provider’s short-lived reconnect feature, such as Browserless’s CDP Browserless.reconnect The original browser process and its reconnect window
Longer gap or state that should survive browser restarts A persistent session API, such as Browserless Session API The provider’s session record until its configured TTL or other limit expires

Browserless describes standard reconnect windows as seconds to a few minutes; its session overview notes a built-in ceiling of up to five minutes. These are provider-level behaviors, not universal API limits, and account or plan maximum duration can still end a session. Check current limits before relying on a particular window. Browserless: Disconnect and reconnect to a browser · Session Management Overview

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reconnect to a live browser process

  1. Request the reconnect endpoint before detaching. Use the browser host’s documented reconnect command or endpoint. Browserless’s short-lived pattern uses its Browserless.reconnect CDP extension and returns a WebSocket endpoint.
  2. Store the endpoint and credentials securely. The endpoint is provider- and protocol-specific. Browserless notes that its returned reconnect endpoint does not itself contain the token, so supply authentication as the provider instructs when reconnecting. Avoid writing token-bearing URLs to logs.
  3. Detach without terminating the remote browser. Use the provider-supported detach behavior. In Browserless’s standard-session flow, Puppeteer’s browser.disconnect() disconnects the client while leaving the remote browser alive; closing the browser instead ends the process.
  4. Reconnect before the timeout. Use a client compatible with that endpoint, then enumerate the available contexts and pages. Select the intended tab rather than assuming the first page is the one you left open.

Browserless’s documentation describes reconnecting with cookies, localStorage, and other state intact while the browser remains available. The endpoint expires when its window elapses; the provider says an unclaimed browser shuts down and a later reconnect can return 404. Browserless reconnect guide · Reconnect to Session

Puppeteer example with a provider-issued endpoint

Use the endpoint returned by the host’s reconnect operation. The exact authentication syntax depends on that provider; Browserless’s example adds its token to the follow-up endpoint. Do not treat the illustrative placeholder below as a universal URL format.

const puppeteer = require('puppeteer');

// Set this to the provider-issued reconnect WebSocket endpoint,
// with authentication added exactly as that provider requires.
const browserWSEndpoint = process.env.BROWSER_WS_ENDPOINT;

(async () => {
  if (!browserWSEndpoint) throw new Error('Set BROWSER_WS_ENDPOINT');

  const browser = await puppeteer.connect({ browserWSEndpoint });
  try {
    const pages = await Promise.all(
      browser.pages().then(pages => pages.map(async (page, index) => ({
        index,
        url: page.url(),
        title: await page.title()
      })))
    );
    console.log(pages);
    // Select the intended page from browser.pages() and continue work.
  } finally {
    // Detach from a remote browser; do not call browser.close() when
    // the provider requires the process to remain alive for reconnection.
    browser.disconnect();
  }
})();

This attaches to an existing browser; it does not create the original reconnect endpoint. Browserless’s short-lived guide shows obtaining browserWSEndpoint through its CDP extension and reconnecting with puppeteer.connect(). See its endpoint and authentication example.

Playwright over CDP

Playwright can attach to an existing Chromium browser through chromium.connectOverCDP(endpoint). After attaching, inspect contexts and pages to locate the target. This is Chromium-only and Playwright characterizes CDP attachment as significantly lower fidelity than its native Playwright-protocol connection; it is not equivalent and does not provide the same attach method for Firefox or WebKit. Playwright BrowserType API

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const { chromium } = require('playwright');

(async () => {
  const endpoint = process.env.BROWSER_WS_ENDPOINT;
  if (!endpoint) throw new Error('Set BROWSER_WS_ENDPOINT');

  const browser = await chromium.connectOverCDP(endpoint);
  const contexts = browser.contexts();
  for (const [contextIndex, context] of contexts.entries()) {
    for (const [pageIndex, page] of context.pages().entries()) {
      console.log({
        contextIndex,
        pageIndex,
        url: page.url(),
        title: await page.title()
      });
    }
  }
  // Choose the expected page, then continue automation.
})();

Browserless says its standard-session reconnect flow relies on Puppeteer’s browser.disconnect(), which Playwright does not expose; it recommends persistent-state sessions for Playwright. Its Session API guide demonstrates attaching with connectOverCDP. Browserless Standard Sessions · Continue browser state across runs

Preserve state across longer gaps or browser restarts

When the browser process need not stay alive, use a session service designed to persist browser state. Browserless’s Session API has explicit create, connect, and stop operations. Its guide sets a TTL, returns separate connect and stop URLs, attaches over WebSocket, disconnects, reconnects, and then deletes the session. Retention is bounded by the configured TTL and provider limits, not permanent. The guide’s example uses a 300,000 ms TTL; that is an example configuration, not a universal default or guarantee.

  1. Create a session through the provider’s REST API and record its returned connection and cleanup details securely.
  2. Connect using the returned WebSocket endpoint and a supported framework/protocol.
  3. Disconnect the client when a run ends, without deleting the persistent session if it must be resumed.
  4. Reconnect while the session remains valid, then inspect contexts and pages as you would after a live-process attach.
  5. Stop/delete the session when finished so its lifecycle is explicit.

For Playwright, this persistent-session route is the documented Browserless recommendation when state must carry across runs. Follow the current Session API guide for request fields and authentication rather than copying endpoint syntax from another provider or API. Browserless Session API: Continue browser state across runs · Session Management Overview

Use the endpoint that matches the next client

Some providers expose more than one endpoint type. Browserless documents BrowserQL endpoints for subsequent BQL queries and WebSocket endpoints for framework connections. A BrowserQL endpoint is not interchangeable with a Puppeteer or Playwright WebSocket endpoint. If handing a session from one client to another, request or retain the endpoint intended for that client and protocol. Browserless: Reconnect using Puppeteer & Playwright

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot failed reconnections

  • 404 or expired endpoint: The reconnect window likely elapsed and the browser shut down. Start a fresh browser, or use a persistent session with a suitable TTL for workflows that routinely pause longer.
  • 401 Unauthorized: Confirm the follow-up connection includes the required credentials. Browserless notes that its returned endpoint may omit the token. Follow the current provider instructions and keep secrets out of logs.
  • Connection succeeds but the wrong page appears: Enumerate contexts and pages, then choose the expected tab. A successful WebSocket handshake does not select the correct page automatically.
  • Reconnect works briefly, then the browser closes: Check the provider’s maximum session duration as well as idle timeout. A plan-level cap can terminate a browser even when a requested idle timeout has not elapsed.
  • Queries fail after changing client: Verify endpoint type. Use the BQL endpoint for BQL operations and the WebSocket endpoint for a framework connection.
  • Playwright features behave differently: Confirm that the target is Chromium and that CDP’s lower-fidelity behavior is acceptable. For Playwright workflows needing supported state across runs, use the provider’s persistent-session path or a native Playwright protocol connection if the host offers one.
  • Remote browser disappears after disconnect: Check whether the client closed the browser instead of detaching, and whether the provider supports that detach pattern for the chosen library. Browserless standard reconnect specifically documents Puppeteer’s browser.disconnect(); it warns that Playwright lacks this method.

Or skip the browser setup

If your goal is to capture a page rather than resume an interactive remote browser, ScreenshotNeo is a website screenshot API and MCP server: it takes a URL and returns an image or PDF, so there is no browser session to reconnect. Its capture flow accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; each cleanup step can be disabled. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, with verdict and billing details in response headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents.

One-call example (replace the URL with the page to capture):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for authentication and options. It includes 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.