# CDP & Puppeteer

Add `"cdp": true` to a launch and the response carries a `cdpUrl` next to `wsUrl`: a browser-level Chrome DevTools Protocol WebSocket. Drive it with Puppeteer, Playwright's `connectOverCDP()` in any language and any recent version, or a raw CDP client — Stagehand, browser-use, chromedp, Rod and most agent frameworks connect this way.

## Launch

```http
POST https://starter.cdpfleet.com/chrome/session
x-api-key: <your key>
{ "proxy": "http://user:pass@proxy.example.com:8080", "headless": "new", "cdp": true }

→ { "sessionId": "…",
    "wsUrl":  "wss://router01.cdpfleet.com/session/…",
    "cdpUrl": "wss://router01.cdpfleet.com/session/…/cdp", … }
```

Available on [Google Chrome](https://cdpfleet.com/docs/browsers/chrome), [Microsoft Edge](https://cdpfleet.com/docs/browsers/edge), [Brave](https://cdpfleet.com/docs/browsers/brave), [Opera](https://cdpfleet.com/docs/browsers/opera), [Yandex Browser](https://cdpfleet.com/docs/browsers/yandex), [Chromium](https://cdpfleet.com/docs/browsers/chromium). Everything else about the session is unchanged: the same proxy, `proxy_rules` and live proxy swap, the same timeouts, threads and billing.

## Puppeteer

```js
// npm install puppeteer-core
import puppeteer from 'puppeteer-core';

const KEY = process.env.CDPFLEET_API_KEY;
const res = await fetch('https://starter.cdpfleet.com/chrome/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', cdp: true }),
});
const { cdpUrl } = await res.json();

const browser = await puppeteer.connect({ browserWSEndpoint: cdpUrl, 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
```

Use `puppeteer-core`: the browser runs on cdpfleet, nothing to download.

## Playwright connectOverCDP

Unlike `connect()`, `connectOverCDP()` doesn't need a client of the server's exact version. You get the Chromium-level API; Playwright features that need its own server protocol (for example tracing to a file on the browser side) behave as with any CDP browser.

 

```node
// npm install playwright@1.60.0
// cdp: true — Playwright's connectOverCDP (any recent version), or Puppeteer:
//   puppeteer.connect({ browserWSEndpoint: cdpUrl, headers: { 'x-api-key': KEY } })
// 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/chrome/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',
    cdp: true,
  }),
});
if (!res.ok) throw new Error(`launch failed: ${res.status} ${await res.text()}`);
const { cdpUrl } = await res.json();

// 2. Connect and drive it
const browser = await chromium.connectOverCDP(cdpUrl, { 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/chrome/session",
    headers={"x-api-key": KEY},
    json={
        "proxy": "http://user:pass@proxy.example.com:8080",
        "headless": "new",
        "cdp": True,
    },
    timeout=60,
)
res.raise_for_status()
cdp_url = res.json()["cdpUrl"]

# 2. Connect and drive it
with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(cdp_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",
          "cdp": true
        }
        """;
    HttpResponse<String> res = HttpClient.newHttpClient().send(
        HttpRequest.newBuilder(URI.create("https://starter.cdpfleet.com/chrome/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 cdpUrl = JsonParser.parseString(res.body()).getAsJsonObject().get("cdpUrl").getAsString();

    // 2. Connect and drive it
    try (Playwright playwright = Playwright.create()) {
      Browser browser = playwright.chromium().connectOverCDP(cdpUrl,
          new BrowserType.ConnectOverCDPOptions().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",
      "cdp": true
    }
    """;
var res = await http.PostAsync("https://starter.cdpfleet.com/chrome/session",
    new StringContent(body, Encoding.UTF8, "application/json"));
if (!res.IsSuccessStatusCode)
    throw new Exception($"launch failed: {(int)res.StatusCode} {await res.Content.ReadAsStringAsync()}");
var cdpUrl = (await res.Content.ReadFromJsonAsync<JsonElement>()).GetProperty("cdpUrl").GetString()!;

// 2. Connect and drive it
using var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.ConnectOverCDPAsync(cdpUrl, new BrowserTypeConnectOverCDPOptions
{
    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",
	  "cdp": true
	}`
	req, _ := http.NewRequest("POST", "https://starter.cdpfleet.com/chrome/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 {
		CdpURL string `json:"cdpUrl"`
	}
	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.ConnectOverCDP(session.CdpURL, playwright.BrowserTypeConnectOverCDPOptions{
		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
}
```

## Raw CDP

Any WebSocket client works. Put the key in the `x-api-key` header, or in the URL when the client can't set headers:

```http
wss://router01.cdpfleet.com/session/…/cdp?api_key=cdpf_…

→ {"id":1,"method":"Browser.getVersion"}
← {"id":1,"result":{"product":"Chrome/154.0.8037.97", …}}
```

## Rules

-   **Same key, same owner:** only the key that launched the session (or an admin) may connect; any other key is refused (`401`/`403`). `/cdp` on a session launched without `cdp` returns `404`.
-   **Both at once is fine:** you can drive one session through `wsUrl` (Playwright) and `cdpUrl` (Puppeteer) together — but disconnecting *either* ends the session and closes the other.
-   **Not every engine:** `"cdp": true` on another browser returns `400` naming the supported ones. Camoufox, Firefox and WebKit don't speak CDP. Patchright and Rebrowser do, but their stealth patches live in the Playwright layer that CDP bypasses — use `wsUrl` with them. Whale crashes when a CDP client opens a tab, so it is excluded.
-   **Detection:** the classic check for a CDP client with `Runtime.enable` on (an error whose `stack` getter fires when the client reads it) no longer fires on today's builds, over `cdpUrl` or `wsUrl` — but `console.log` still costs measurably more in a page under Playwright or Puppeteer than under Patchright, so a timing script can tell ([CDP detectability](https://cdpfleet.com/docs/cases/cdp-detectability)). When that matters, use a stealth build — see [stealth builds](https://cdpfleet.com/docs/cases/stealth-builds).

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