Playwright Cloud Browser — Remote CDP Connection
Run Playwright in the cloud with a Lexmount remote Chromium session. Connect with connectOverCDP, automate a page, and close the session safely.
Lexmount Cloud Browser API runs the browser remotely while your Playwright script runs in your own application. Create a Chromium session, connect with chromium.connectOverCDP, and use the returned browser context to interact with pages.
This guide is for browser automation and multi-step interactions. If you only need structured text from a public URL, start with the Web Fetch API.
Install
These pinned example dependencies require Node.js 20 or later.
npm install lexmount@0.6.1 playwright@1.63.0Set the credentials from getting started. Save this complete script as example.mjs, then run node example.mjs. No local browser download is required.
import { chromium } from 'playwright';
import { Lexmount } from 'lexmount';
const client = new Lexmount();
let session;
let browser;
try {
session = await client.sessions.create({ browserMode: 'normal' });
if (!session.connectUrl) throw new Error('Session has no CDP URL');
browser = await chromium.connectOverCDP(session.connectUrl);
const context = browser.contexts()[0];
if (!context) throw new Error('Default browser context is unavailable');
const page = context.pages()[0] ?? await context.newPage();
await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
console.log(await page.title());
} finally {
try {
await browser?.close();
} finally {
try {
await session?.close();
} finally {
client.close();
}
}
}Expected output: Example Domain. The script connects to a remote Chromium session and closes the session even after a navigation failure. Treat the returned connection URL as a credential.
Continue with page interaction, content extraction, and lifecycle details.
Common remote Playwright questions
Do I need to install a local browser?
No browser download is required for this example: it connects to an existing remote Chromium session instead of calling chromium.launch(). Install the example dependencies and configure the API key and Project ID before running the script.
What should I check if the CDP connection fails?
Create a fresh session and use its returned connectUrl without rewriting it. Check the project credentials, regional API endpoint, session status, and network access. Do not copy connection URLs into public logs. See session lifecycle for cleanup and failure handling.
How much does running Playwright in the cloud cost?
The remote session uses your project's browser allowance and concurrency capacity. Closing it in finally releases the session after both successful and failed runs. Compare the Free plan and current limits on the cloud browser pricing page, and read the billing guide.
