# SDKs

Small libraries for Node.js, Python, Java, C# and Go that wrap the cdpfleet API: launch a browser (retrying when the fleet is busy, as the API asks), connect **your own** Playwright to it, and close it — plus keep\_alive reconnects, live links, proxy swaps, recordings and your usage. You don't need them: every example on this site also works with plain Playwright and one HTTP call. They just remove the boilerplate.

 

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

const fleet = new Cdpfleet(); // reads CDPFLEET_API_KEY
const options = {
  proxy: 'http://user:pass@proxy.example.com:8080',
  headless: 'new',
};

const session = await fleet.launch('chromium', options);
const browser = await session.connect(chromium);
const page = await browser.newPage();
await page.goto('https://example.com');
console.log(await page.title());
await session.close(); // ends the session and stops billing
```

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

fleet = Cdpfleet()  # reads CDPFLEET_API_KEY
options = {
    "proxy": "http://user:pass@proxy.example.com:8080",
    "headless": "new",
}

with sync_playwright() as p, fleet.launch("chromium", options) as session:
    browser = session.connect(p.chromium)
    page = browser.new_page()
    page.goto("https://example.com")
    print(page.title())
# leaving the block closes the session and stops billing
```

```java
// The cdpfleet SDK for Java (Maven Central) isn't published yet, so this is the plain
// Playwright version — it works today. The SDK will remove the launch boilerplate.
// 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
// The cdpfleet SDK for C# (NuGet) isn't published yet, so this is the plain
// Playwright version — it works today. The SDK will remove the launch boilerplate.
// 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/cdpfleet/cdpfleet/sdk/go 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
package main

import (
	"encoding/json"
	"fmt"
	"log"

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

func main() {
	fleet, err := cdpfleet.New() // reads CDPFLEET_API_KEY
	if err != nil {
		log.Fatal(err)
	}
	var options cdpfleet.Options
	if err := json.Unmarshal([]byte(`{
	  "proxy": "http://user:pass@proxy.example.com:8080",
	  "headless": "new"
	}`), &options); err != nil {
		log.Fatal(err)
	}

	pw, err := playwright.Run(&playwright.RunOptions{SkipInstallBrowsers: true})
	if err != nil {
		log.Fatal(err)
	}
	defer pw.Stop()

	session, err := fleet.Launch("chromium", options)
	if err != nil {
		log.Fatal(err)
	}
	defer session.Close() // ends the session and stops billing

	browser, err := session.Connect(pw.Chromium)
	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)
}
```

The [code builder](https://cdpfleet.com/docs/builder) writes this for any browser and options — switch it between **SDK** and **Plain**.

## Install

Node.js, Python and Go are published (0.1.1). The C# and Java packages are on their way to NuGet and Maven Central — until then they build from [their source on GitHub](https://github.com/cdpfleet/cdpfleet/tree/main/sdk).

| Language | Package | Playwright (yours) |
| --- | --- | --- |
| Node.js | `npm install cdpfleet` (ESM, TypeScript types) | `playwright@1.60.0` |
| Python | `pip install cdpfleet` (sync and async) | `playwright==1.60.0` |
| Java | Maven `com.cdpfleet:cdpfleet:0.1.0` (coming soon) | `com.microsoft.playwright:playwright:1.60.0` |
| C# | `dotnet add package Cdpfleet` (coming soon) | `Microsoft.Playwright 1.60.0` |
| Go | `go get github.com/cdpfleet/cdpfleet/sdk/go` | `playwright-go v0.6000.0` |

The SDKs never bundle Playwright: you pass your own browser type (`chromium`, `firefox`, `webkit`), so you choose the client version — 1.60 for every browser, 1.52 for [Rebrowser](https://cdpfleet.com/docs/browsers/rebrowser). Sources, specification and examples: [github.com/cdpfleet/cdpfleet/sdk](https://github.com/cdpfleet/cdpfleet/tree/main/sdk).

## What they do for you

-   **Launch with the right retries:** `503` (fleet busy) and `429` (rate or thread limit) are retried, honouring `Retry-After`, for up to two minutes; quota errors and bad requests fail at once with the API's error code.
-   **Connect, or connect over CDP:** `session.connect(chromium)` or `session.connectOverCDP(chromium)` (launch with `cdp: true`) — the key goes in the header.
-   **One-step connect URL:** `fleet.connectUrl('chrome', { headless: 'new' })` (Python `connect_url`, Go `ConnectURL`) returns a [launch-on-connect](https://cdpfleet.com/docs/connect) URL — `chromium.connect(url, { headers: fleet.headers() })` launches and connects in one step, and the URL drops straight into Playwright Test's `wsEndpoint`. `cdp: true` gives a `/cdp` URL for `connectOverCDP` or Puppeteer. Node.js, Python and Go for now.
-   **keep\_alive:** call `connect` again after a disconnect to re-attach (the SDK waits out the few seconds the router needs); `close()` ends a keep\_alive session, which `browser.close()` alone doesn't.
-   **Live view and proxy swap:** `session.liveLink('control')` returns a [live link](https://cdpfleet.com/docs/live-view); `session.swapProxy(proxy, rules)` moves a `proxy_updatable` session to another proxy.
-   **Account API:** usage, live threads, session history, [recordings](https://cdpfleet.com/docs/recordings) (list, link, delete) and your residential balance.

## Names in each language

|  | Node.js | Python | Java | C# | Go |
| --- | --- | --- | --- | --- | --- |
| Client | `new Cdpfleet()` | `Cdpfleet()` / `AsyncCdpfleet()` | `new Cdpfleet()` | `new CdpfleetClient()` | `cdpfleet.New()` |
| Launch | `await fleet.launch(name, options)` | `fleet.launch(name, options)` | `fleet.launch(name, Map)` | `await fleet.LaunchAsync(name, options)` | `fleet.Launch(name, cdpfleet.Options{…})` |
| Connect URL | `fleet.connectUrl(name, options)` | `fleet.connect_url(name, options)` | — | — | `fleet.ConnectURL(name, cdpfleet.Options{…})` |
| Done | `await session.close()` | `with … as session:` | try-with-resources | `await using var session` | `defer session.Close()` |

The API key comes from `CDPFLEET_API_KEY` unless you pass one. For AI agents, see the [MCP server](https://cdpfleet.com/docs/mcp).

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