Skip to Content
Browser API

Quickstart

Connect Puppeteer or Playwright to RunHBrowser, open a page, and print its title.

Before you start

  1. Create a browser account on the Browser API page of the dashboard and copy its connection URL. It looks like this:

    wss://<login>:<password>@browser.runharvester.com
  2. Keep the URL secret, because it contains the password. The examples read it from the BROWSER_WS_URL environment variable.

  3. Make sure your balance covers at least the first billing portion; otherwise the connection is refused with 402. See Billing.

Puppeteer and Playwright turn the credentials in the URL into an HTTP Basic Authorization header themselves. Do not append a query string to the URL.

Connect and read a title

Each example connects, opens https://example.com, prints the page title, and closes the browser.

import puppeteer from "puppeteer-core";

const browser = await puppeteer.connect({
  browserWSEndpoint: process.env.BROWSER_WS_URL,
});

const page = await browser.newPage();
await page.goto("https://example.com");
console.log(await page.title());

await browser.close();

In Node.js, puppeteer-core and playwright-core are enough: the browser runs remotely, so no local browser download is needed.

If the connection fails before the WebSocket opens, the response is a JSON error such as 401 UNAUTHORIZED or 402 INSUFFICIENT_BALANCE. See Errors and close codes.

Choose a country or proxy type

Add modifiers to the login to steer the session. For example, to exit in Germany through a residential address:

wss://<login>-country-de-type-residential:<password>@browser.runharvester.com

See Connection URL for every modifier.

Reconnect to the same browser

Name the session with session-<id> and a dropped client can reconnect to the same browser and its tabs within 60 seconds. Call disconnect() instead of close() to leave the browser running.

import puppeteer from "puppeteer-core";

// BROWSER_WS_URL carries the session modifier, for example:
// wss://<login>-session-job42:<password>@browser.runharvester.com
const url = process.env.BROWSER_WS_URL;

const first = await puppeteer.connect({ browserWSEndpoint: url });
const page = await first.newPage();
await page.goto("https://example.com");
await first.disconnect(); // the browser keeps running for 60 seconds

// Within 60 seconds: same URL, same browser, same tabs.
const second = await puppeteer.connect({ browserWSEndpoint: url });
const [reopened] = (await second.pages()).filter((p) => p.url().startsWith("https://example.com"));
console.log(await reopened.title());

await second.close();

A second client that uses the same session-<id> while the first is still connected is refused with 409 SESSION_IN_USE.

Keep cookies between sessions with a profile

Add a pid-<profileId> modifier with a profile id from the dashboard. The profile saves cookies, localStorage, sessionStorage, and IndexedDB when the session ends, and restores them the next time you connect with the same id.

import puppeteer from "puppeteer-core";

// BROWSER_WS_URL carries the profile modifier, for example:
// wss://<login>-pid-<64 hex characters>:<password>@browser.runharvester.com
const browser = await puppeteer.connect({
  browserWSEndpoint: process.env.BROWSER_WS_URL,
});

const page = (await browser.pages())[0] ?? (await browser.newPage());
await page.goto("https://example.com");
console.log(await page.cookies());

await browser.close();

Only one live session per profile is allowed; a second connection gets 409 PROFILE_BUSY. See Profiles and sessions.

Last updated on

On this page