[cdpfleet](https://cdpfleet.com/) / How it works

How it works

# Four steps. *No browser infrastructure.*

Ask for a browser with one HTTPS call, connect your Playwright code to the WebSocket it returns, and close it when you're done. Everything between — servers, browser builds, displays, updates — is ours.

[Quickstart](https://cdpfleet.com/docs/quickstart)[Code builder](https://cdpfleet.com/docs/builder)

-   **1**HTTPS call
-   **5**languages
-   **1 s**billing resolution

## The four steps

1.  **Request a browser:** `POST /<browser>/session` with your API key and a proxy — e.g. `POST https://starter.cdpfleet.com/camoufox/session`.
2.  **Get your socket:** the response carries a single-use `wsUrl` on one of our routers, plus the session id and its thread weight.
3.  **Connect your code:** `chromium`/`firefox`/`webkit.connect(wsUrl)` and use it like a local browser — pages, contexts, network interception, screenshots. Or launch with `"cdp": true` and use Puppeteer.
4.  **Close to stop billing:** `browser.close()` frees the browser at once; every session's start and end is in your usage log.

The four steps as one program

 

```node
// npm install playwright@1.60.0
// Browsers run on cdpfleet, so no `npx playwright install` is needed.
import { chromium } from 'playwright';

const KEY = process.env.CDPFLEET_API_KEY;

// 1. Launch the browser
const res = await fetch('https://starter.cdpfleet.com/chromium/session', {
  method: 'POST',
  headers: { 'x-api-key': KEY, 'content-type': 'application/json' },
  body: JSON.stringify({
    proxy: 'http://user:pass@proxy.example.com:8080',
    headless: 'new',
  }),
});
if (!res.ok) throw new Error(`launch failed: ${res.status} ${await res.text()}`);
const { wsUrl } = await res.json();

// 2. Connect and drive it
const browser = await chromium.connect(wsUrl, { headers: { 'x-api-key': KEY } });
const page = await browser.newPage();
await page.goto('https://example.com');
console.log(await page.title());
await browser.close(); // ends the session and stops billing
```

```python
# pip install playwright==1.60.0 requests
# Browsers run on cdpfleet, so no `playwright install` is needed.
import os
import requests
from playwright.sync_api import sync_playwright

KEY = os.environ["CDPFLEET_API_KEY"]

# 1. Launch the browser
res = requests.post(
    "https://starter.cdpfleet.com/chromium/session",
    headers={"x-api-key": KEY},
    json={
        "proxy": "http://user:pass@proxy.example.com:8080",
        "headless": "new",
    },
    timeout=60,
)
res.raise_for_status()
ws_url = res.json()["wsUrl"]

# 2. Connect and drive it
with sync_playwright() as p:
    browser = p.chromium.connect(ws_url, headers={"x-api-key": KEY})
    page = browser.new_page()
    page.goto("https://example.com")
    print(page.title())
    browser.close()  # ends the session and stops billing
```

```java
// Maven: com.microsoft.playwright:playwright:1.60.0  and  com.google.code.gson:gson:2.11.0
// Run with PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1: browsers run on cdpfleet.
import com.google.gson.JsonParser;
import com.microsoft.playwright.*;
import java.net.URI;
import java.net.http.*;
import java.util.Map;

public class Example {
  public static void main(String[] args) throws Exception {
    String key = System.getenv("CDPFLEET_API_KEY");

    // 1. Launch the browser
    String body = """
        {
          "proxy": "http://user:pass@proxy.example.com:8080",
          "headless": "new"
        }
        """;
    HttpResponse<String> res = HttpClient.newHttpClient().send(
        HttpRequest.newBuilder(URI.create("https://starter.cdpfleet.com/chromium/session"))
            .header("x-api-key", key)
            .header("content-type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(body))
            .build(),
        HttpResponse.BodyHandlers.ofString());
    if (res.statusCode() != 200) {
      throw new RuntimeException("launch failed: " + res.statusCode() + " " + res.body());
    }
    String wsUrl = JsonParser.parseString(res.body()).getAsJsonObject().get("wsUrl").getAsString();

    // 2. Connect and drive it
    try (Playwright playwright = Playwright.create()) {
      Browser browser = playwright.chromium().connect(wsUrl,
          new BrowserType.ConnectOptions().setHeaders(Map.of("x-api-key", key)));
      Page page = browser.newPage();
      page.navigate("https://example.com");
      System.out.println(page.title());
      browser.close(); // ends the session and stops billing
    }
  }
}
```

```csharp
// dotnet add package Microsoft.Playwright --version 1.60.0
// Browsers run on cdpfleet, so no `playwright install` is needed.
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using Microsoft.Playwright;

var key = Environment.GetEnvironmentVariable("CDPFLEET_API_KEY")!;

// 1. Launch the browser
using var http = new HttpClient();
http.DefaultRequestHeaders.Add("x-api-key", key);
var body = """
    {
      "proxy": "http://user:pass@proxy.example.com:8080",
      "headless": "new"
    }
    """;
var res = await http.PostAsync("https://starter.cdpfleet.com/chromium/session",
    new StringContent(body, Encoding.UTF8, "application/json"));
if (!res.IsSuccessStatusCode)
    throw new Exception($"launch failed: {(int)res.StatusCode} {await res.Content.ReadAsStringAsync()}");
var wsUrl = (await res.Content.ReadFromJsonAsync<JsonElement>()).GetProperty("wsUrl").GetString()!;

// 2. Connect and drive it
using var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.ConnectAsync(wsUrl, new BrowserTypeConnectOptions
{
    Headers = new Dictionary<string, string> { ["x-api-key"] = key },
});
var page = await browser.NewPageAsync();
await page.GotoAsync("https://example.com");
Console.WriteLine(await page.TitleAsync());
await browser.CloseAsync(); // ends the session and stops billing
```

```go
// go get github.com/playwright-community/playwright-go@v0.6000.0
//
// One-time driver setup (needs Node.js 18+): playwright-go can no longer download the
// 1.60.0 driver itself, so build it from npm and point PLAYWRIGHT_DRIVER_PATH at it:
//   mkdir -p ~/.cache/pw-driver-1.60.0 && cd ~/.cache/pw-driver-1.60.0 &&
//     curl -sL https://registry.npmjs.org/playwright-core/-/playwright-core-1.60.0.tgz | tar xz &&
//     ln -sf "$(command -v node)" node
//   export PLAYWRIGHT_DRIVER_PATH=~/.cache/pw-driver-1.60.0
// Browsers run on cdpfleet, so no browsers are downloaded (SkipInstallBrowsers).
package main

import (
	"encoding/json"
	"fmt"
	"io"
	"log"
	"net/http"
	"os"
	"strings"

	"github.com/playwright-community/playwright-go"
)

func main() {
	key := os.Getenv("CDPFLEET_API_KEY")

	// 1. Launch the browser
	body := `{
	  "proxy": "http://user:pass@proxy.example.com:8080",
	  "headless": "new"
	}`
	req, _ := http.NewRequest("POST", "https://starter.cdpfleet.com/chromium/session", strings.NewReader(body))
	req.Header.Set("x-api-key", key)
	req.Header.Set("content-type", "application/json")
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()
	if res.StatusCode != http.StatusOK {
		msg, _ := io.ReadAll(res.Body)
		log.Fatalf("launch failed: %s %s", res.Status, msg)
	}
	var session struct {
		WsURL string `json:"wsUrl"`
	}
	if err := json.NewDecoder(res.Body).Decode(&session); err != nil {
		log.Fatal(err)
	}

	// 2. Connect and drive it (Install fetches only the Playwright driver, once)
	opts := &playwright.RunOptions{SkipInstallBrowsers: true}
	if err := playwright.Install(opts); err != nil {
		log.Fatal(err)
	}
	pw, err := playwright.Run(opts)
	if err != nil {
		log.Fatal(err)
	}
	defer pw.Stop()
	browser, err := pw.Chromium.Connect(session.WsURL, playwright.BrowserTypeConnectOptions{
		Headers: map[string]string{"x-api-key": key},
	})
	if err != nil {
		log.Fatal(err)
	}
	page, err := browser.NewPage()
	if err != nil {
		log.Fatal(err)
	}
	if _, err := page.Goto("https://example.com"); err != nil {
		log.Fatal(err)
	}
	title, _ := page.Title()
	fmt.Println(title)
	browser.Close() // ends the session and stops billing
}
```

## What you choose per launch

### The browser

12 desktop browsers with channels and pinned versions, and phone engines in early access.

[Learn more →](https://cdpfleet.com/browsers)

### The proxy

Every session goes through a proxy: yours, a pool with per-host rules, or the residential proxy.

[Learn more →](https://cdpfleet.com/residential-proxy)

### Headless or headful

A headless browser takes 1 thread, a headful one 2.

[Learn more →](https://cdpfleet.com/threads)

### Timeouts and extras

Idle and overall timeouts, `keep_alive`, profiles, recordings, live view.

[Learn more →](https://cdpfleet.com/docs/browsers/chrome)

## Errors you can act on

A refused launch says why, with a status and an `error` code: no free thread (`429 threads_exceeded`), quota used up, the fleet momentarily busy (`503`, retry with backoff). Retry `503` and respect `Retry-After` on `429`; other `4xx` need fixing. The [worker-pool case](https://cdpfleet.com/docs/cases/worker-pool) has a complete retry loop.

## Related

Cases, recipes, posts and comparisons about this — updated as new ones are published.

### Reference docs

The details, options and errors.

-   [Quickstart](https://cdpfleet.com/docs/quickstart)Your first session.
-   [Sessions & billing](https://cdpfleet.com/docs/sessions)Lifetime, timeouts and metering.
-   [Errors & limits](https://cdpfleet.com/docs/errors)Every status and what to do.
-   [SDKs](https://cdpfleet.com/docs/sdk)Client libraries that retry for you.

### Cases 3

Real problems solved end to end, run on production in five languages.

-   [Case 33: When is a page ready? commit, domcontentloaded, load, networkidle or a selector](https://cdpfleet.com/docs/cases/wait-strategies)Five ways to wait for a page, timed on a static catalogue, a big article and a page that renders its data late — and how many data items were actually there when…[Code on GitHub](https://github.com/cdpfleet/cdpfleet/tree/main/cases/33-wait-strategies)
-   [Case 20: Three visitors, one thread: browser contexts instead of sessions](https://cdpfleet.com/docs/cases/contexts-not-sessions)Cookies, storage, locale and clock isolated per persona inside a single browser session — what a context gives you for free, what it shares, and the proxy surprise…[Code on GitHub](https://github.com/cdpfleet/cdpfleet/tree/main/cases/20-contexts-not-sessions)
-   [Case 10: A thread-aware worker pool: one session per page vs. reusing sessions](https://cdpfleet.com/docs/cases/worker-pool)24 pages on 6 parallel workers, two strategies, with the retries the API asks for. Reusing sessions is faster and costs a fraction of the thread time.[Code on GitHub](https://github.com/cdpfleet/cdpfleet/tree/main/cases/10-worker-pool)

## Read next

[Threads →](https://cdpfleet.com/threads)[Browsers →](https://cdpfleet.com/browsers)[Launch interactive →](https://cdpfleet.com/launch-interactive)[Pricing →](https://cdpfleet.com/pricing)

---
Source: https://cdpfleet.com/how-it-works · Markdown: https://cdpfleet.com/how-it-works.md · All docs for AI tools: https://cdpfleet.com/llms.txt
