Connect Puppeteer To BlitzBrowser

To connect Puppeteer to BlitzBrowser, you have to change the method puppeteer.launch() to puppeteer.connect({ ... }).

Code Example

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

import puppeteer from 'puppeteer';

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

const context = await browser.createBrowserContext();
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