Basic Puppeteer Connection
Connect an existing Puppeteer script to Browserless by replacing puppeteer.launch() with a single puppeteer.connect() call.
- A Browserless API token from your account dashboard
Steps
- JavaScript
- TypeScript
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.
1. Install dependencies
npm install puppeteer-core
npm install --save-dev typescript @types/node
Use puppeteer-core — it skips bundling local browser binaries since you're connecting to Browserless instead.
2. Replace launch with connect
import puppeteer, { Browser } from 'puppeteer-core';
const browser: 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
npx ts-node script.ts
Connection options
Append options to the WebSocket URL as query parameters:
| Parameter | Description |
|---|---|
token | Your Browserless API token (required) |
blockAds=true | Block ad network requests |
profile | Load a saved authenticated profile |
solveCaptchas=true | Enable 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
- Basic Playwright Connection — the same pattern for Playwright
- Save Logins to Authenticated Profiles — persist login state across sessions
- Take a Screenshot — capture pages using the REST API instead