Basic Playwright Connection
Connect an existing Playwright script to Browserless by replacing chromium.launch() with a single connectOverCDP() call.
- A Browserless API token from your account dashboard
Steps
- JavaScript
- Python
- TypeScript
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.
1. Install dependencies
pip install playwright
No need to install local browser binaries — you're connecting to Browserless instead of launching a local browser.
2. Replace launch with connect_over_cdp
from playwright.sync_api import sync_playwright
TOKEN = 'YOUR_API_TOKEN_HERE'
WS_ENDPOINT = f'wss://production-sfo.browserless.io?token={TOKEN}'
with sync_playwright() as playwright:
# Before — runs a local browser.
# browser = playwright.chromium.launch()
# After — runs on Browserless.
browser = playwright.chromium.connect_over_cdp(WS_ENDPOINT)
try:
# Use the default context — new_context() doesn't inherit launch settings.
context = browser.contexts[0]
page = context.new_page()
page.goto('https://example.com')
print('Title:', page.title())
finally:
# Always close to release the session even on error.
browser.close()
3. Run the script
python script.py
1. Install dependencies
npm install playwright-core
npm install --save-dev typescript @types/node
Use playwright-core — it skips bundling local browser binaries since you're connecting to Browserless instead.
2. Replace launch with connectOverCDP
import { chromium, Browser } from 'playwright-core';
const browser: 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
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 Puppeteer Connection — the same pattern for Puppeteer
- Save Logins to Authenticated Profiles — persist login state across sessions
- Take a Screenshot — capture pages using the REST API instead