Connect Playwright To BlitzBrowser

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

How to connect

To connect your code, you have to replace launch() with connectOverCDP(`...`). We suggest to pass the ACCESS_KEY as an environment variable to avoid hardcoding your access key directly in the code. The connectOverCDP(`...`) method establishes a connection between Playwright to a remote browser. Playwright will get full control of one of our browsers via the Chrome DevTools Protocol (CDP). Once you disconnect from the browser, the remote browser is killed.

import { chromium } from 'playwright';

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

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

// ...

await browser.close();

Playwright CDP Parameters

You can find all the parameters available to configure your Chrome DevTools Protocol URL when connecting to our browsers here.