Connect Playwright To BlitzBrowser

To connect Playwright to BlitzBrowser, you have to change the method launch() to connectOverCDP(`...`).

Code Example

In this example, we've replaced launch() with connectOverCDP(`...`). We've also introduced the BLITZBROWSER_ACCESS_KEY environment variable to avoid hardcoding your access key directly in the code. The connectOverCDP(`...`) establishes a connection between your Playwright instance and BlitzBrowser via the Chrome DevTools Protocol (CDP). An headless browser will be assigned to your connection until the browser is closed.

import { chromium } from 'playwright';

// const browser = await chromium.launch();
const browser = await chromium.connectOverCDP(
    `wss://cdp.blitzbrowser.com?accessKey=${process.env.BLITZBROWSER_ACCESS_KEY}`
);

const context = await browser.newContext();
const page = await context.newPage();

// ...

await browser.close();

Contribute to the Docs

Found an issue or have an idea for an improvement? Our documentation is open source. Feel free to contribute directly on GitHub.

GitHub logo GitHub Project