Integrations

Playwright Integration

Connect Playwright to Browserize instances in three lines of code.

Quick Start

Connect to a remote Browserize browser instance using the CDP endpoint URL. Add your API key as a header and you're ready to go.

TypeScript / JavaScript
import { chromium } from "playwright";

const browser = await chromium.connectOverCDP(
  "wss://browserize.io/api/v1/browsers/{id}/cdp",
  {
    headers: { Authorization: "Bearer bz_key_xxx" },
  }
);

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

await browser.close();

CDP Connection String

Each browser instance exposes a unique WebSocket endpoint for Chrome DevTools Protocol (CDP) connections. The connection string follows this format:

wss://browserize.io/api/v1/browsers/{browser_id}/cdp
{browser_id}

The unique identifier returned when you create a browser via the API.

Authorization Header

Send your API key as a Bearer token. Keys are scoped to your project and can be rotated from the dashboard.

Full Working Example

A complete script that navigates to a page, interacts with elements, and takes a screenshot.

TypeScript — navigation & assertions
import { chromium } from "playwright";

async function run() {
  const browser = await chromium.connectOverCDP(
    "wss://browserize.io/api/v1/browsers/bz_br_abc123/cdp",
    {
      headers: { Authorization: "Bearer bz_key_xxx" },
      timeout: 30_000,
    }
  );

  const page = await browser.newPage();

  // Navigate
  await page.goto("https://news.ycombinator.com", {
    waitUntil: "networkidle",
  });

  // Assert
  const title = await page.title();
  console.assert(title.includes("Hacker News"), "Unexpected title");

  // Interact
  await page.click(".hnname a");

  // Screenshot
  await page.screenshot({ path: "hn.png", fullPage: true });

  await browser.close();
  console.log("Done!");
}

run().catch(console.error);

Python (Playwright)

The same flow works with Playwright for Python. Install with pip install playwright.

Python
import asyncio
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.connect_over_cdp(
            "wss://browserize.io/api/v1/browsers/bz_br_abc123/cdp",
            headers={"Authorization": "Bearer bz_key_xxx"},
        )
        page = await browser.new_page()
        await page.goto("https://example.com")
        print(await page.title())
        await browser.close()

asyncio.run(main())

Production Tips

Connection Pooling

Reuse browser instances across tasks instead of creating a new one for every job. Set a maximum concurrent page limit and queue requests when the pool is full.

Error Handling

Wrap connection and navigation calls in try/catch blocks. CDP connections can drop due to network issues — implement retry logic with exponential backoff for transient failures.

Timeouts

Always set explicit timeouts on both the CDP connection and individual navigation calls. A 30-second default is recommended, with longer limits for slow-loading pages.