For AI agents: a documentation index is available at /llms.txt
Skip to main content

Basic Puppeteer Connection

Connect an existing Puppeteer script to Browserless by replacing puppeteer.launch() with a single puppeteer.connect() call.

Prerequisites

Steps

View Full Code on GitHub

1. Install dependencies

npm install puppeteer-core

Use puppeteer-core instead of puppeteer — it doesn't bundle local browser binaries, which you don't need when connecting to Browserless.

2. Replace launch with connect

The only change needed is swapping puppeteer.launch() for puppeteer.connect() with the Browserless WebSocket endpoint:

// Before — runs a local browser.
// const browser = await puppeteer.launch();

// After — runs on Browserless.
import puppeteer from 'puppeteer-core';

const browser = await puppeteer.connect({
browserWSEndpoint: 'wss://production-sfo.browserless.io?token=YOUR_API_TOKEN_HERE',
});

try {
const page = await browser.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle2' });
console.log('Title:', await page.title());
} finally {
// Always close to release the session even on error.
await browser.close();
}

3. Run the script

node script.mjs

The script runs against a cloud browser on Browserless instead of a local Chrome install.

Connection options

Append options to the WebSocket URL as query parameters:

ParameterDescription
tokenYour Browserless API token (required)
blockAds=trueBlock ad network requests
profileLoad a saved authenticated profile
solveCaptchas=trueEnable automatic CAPTCHA solving

For stealth mode, change the path instead of adding a query parameter:

wss://production-sfo.browserless.io/stealth?token=YOUR_API_TOKEN_HERE

Example with stealth and additional options:

wss://production-sfo.browserless.io/stealth?token=YOUR_API_TOKEN_HERE&blockAds=true

Next steps