Skip to main content
Version: v2

Puppeteer

info

Currently, Browserless V2 is available in production via two domains: production-sfo.browserless.io and production-lon.browserless.io

Puppeteer is well-supported by browserless, and is easy to upgrade an existing service or app to use it.

Basic Usage

In order to use the browserless service, simply change the following:

Before browserless

import puppeteer from "puppeteer";

const browser = await puppeteer.launch();
const page = await browser.newPage();
// ...

After browserless

import puppeteer from "puppeteer";

const browser = await puppeteer.connect({
browserWSEndpoint: `wss://production-sfo.browserless.io?token=GOES-HERE`,
});
const page = await browser.newPage();
info

If you're running the docker container to replace the location of wss://production-sfo.browserless.io/ to wherever your container is running.

Specifying launch flags

You can specify launch-arguments through an object sent on a query string inside the browserWSEndpoint. As an example, if you want to start the browser with a pre-defined width and height, in headful mode and setting stealth, you can specify it like so:

import puppeteer from "puppeteer-core";

const launchArgs = JSON.stringify({
args: [`--window-size=1920,1080`, `--user-data-dir=/tmp/chrome/data-dir`],
headless: false,
stealth: true,
timeout: 5000,
});

const browser = await puppeteer.connect({
browserWSEndpoint: `wss://production-sfo.browserless.io/?token=GOES-HERE&launch=${launchArgs}`,
});

//...