# Quickstart (/browser-api/quickstart)

## Before you start [#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:

   ```text
   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](/browser-api/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 [#connect-and-read-a-title]

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

<Tabs defaultValue="puppeteer">
<TabsList>
<TabsTrigger value="puppeteer">
Puppeteer (Node.js)
</TabsTrigger>

<TabsTrigger value="playwright-node">
Playwright (Node.js)
</TabsTrigger>

<TabsTrigger value="playwright-python">
Playwright (Python)
</TabsTrigger>

<TabsTrigger value="playwright-java">
Playwright (Java)
</TabsTrigger>

<TabsTrigger value="playwright-dotnet">
Playwright (.NET)
</TabsTrigger>
</TabsList>

<Tab value="puppeteer">
```javascript
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();
```
</Tab>

<Tab value="playwright-node">
```javascript
import { chromium } from "playwright-core";

const browser = await chromium.connectOverCDP(process.env.BROWSER_WS_URL);

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

await browser.close();
```
</Tab>

<Tab value="playwright-python">
```python
import os

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(os.environ["BROWSER_WS_URL"])

    page = browser.new_page()
    page.goto("https://example.com")
    print(page.title())

    browser.close()
```
</Tab>

<Tab value="playwright-java">
```java
import com.microsoft.playwright.Browser;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;

public class Main {
  public static void main(String[] args) {
    try (Playwright playwright = Playwright.create()) {
      Browser browser = playwright.chromium().connectOverCDP(System.getenv("BROWSER_WS_URL"));

      Page page = browser.newPage();
      page.navigate("https://example.com");
      System.out.println(page.title());

      browser.close();
    }
  }
}
```
</Tab>

<Tab value="playwright-dotnet">
```csharp
using Microsoft.Playwright;

using var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.ConnectOverCDPAsync(
    Environment.GetEnvironmentVariable("BROWSER_WS_URL")!);

var page = await browser.NewPageAsync();
await page.GotoAsync("https://example.com");
Console.WriteLine(await page.TitleAsync());

await browser.CloseAsync();
```
</Tab>
</Tabs>

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](/browser-api/errors).

## Choose a country or proxy type [#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:

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

See [Connection URL](/browser-api/connection-url) for every modifier.

## Reconnect to the same browser [#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.

```javascript
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 [#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.

```javascript
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](/browser-api/profiles-and-sessions).