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

Basic Playwright Connection

Connect an existing Playwright script to Browserless by replacing chromium.launch() with a single connectOverCDP() call.

Prerequisites

Steps

View Full Code on GitHub

1. Install dependencies

npm install playwright-core

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

2. Replace launch with connectOverCDP

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

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

// After — runs on Browserless.
import { chromium } from 'playwright-core';

const browser = await chromium.connectOverCDP(
'wss://production-sfo.browserless.io?token=YOUR_API_TOKEN_HERE'
);

try {
// Use the default context — browser.newPage() creates a new context that
// doesn't inherit proxy, profile, or launch settings.
const context = browser.contexts()[0];
const page = await context.newPage();
await page.goto('https://example.com', { waitUntil: 'networkidle' });
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