Connect with Playwright
Connect with Playwright.
Install
These pinned example dependencies require Node.js 20 or later.
npm install lexmount@0.5.17 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.
