Node.js SDK Quick Start
Create a cloud browser session from TypeScript and connect through Playwright CDP.
The Node.js SDK follows the same path as the console Quick Start: API Key, Session, View verification, then code connection. Verify session creation and View in the console before wiring it into a service.
1. Install dependencies
npm install lexmount@0.5.14 playwright dotenv
npx playwright install chromiumIf you are running examples from the SDK repository:
npm install
npm run build
cd examples
npm install2. Configure environment variables
LEXMOUNT_API_KEY=sk_...
LEXMOUNT_PROJECT_ID=project_...
LEXMOUNT_BASE_URL=https://api.lexmount.cnGet API Key and Project ID from Settings / API Keys in the console.
3. Create a session
import { Lexmount } from 'lexmount';
const client = new Lexmount();
const session = await client.sessions.create({
browserMode: 'normal',
});
console.log('session id:', session.id);
console.log('view url:', session.inspectUrl);
console.log('connect url:', session.connectUrl);
await session.close();
client.close();This maps to “create session” in the console. inspectUrl opens remote View, while connectUrl is the CDP endpoint for Playwright / Puppeteer.
4. Connect with Playwright
import { config } from 'dotenv';
import { chromium } from 'playwright';
import { Lexmount } from 'lexmount';
config();
const client = new Lexmount();
const session = await client.sessions.create({ browserMode: 'normal' });
try {
const browser = await chromium.connectOverCDP(session.connectUrl);
const context = browser.contexts()[0] ?? (await browser.newContext());
const page = context.pages()[0] ?? (await context.newPage());
await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
console.log('title:', await page.title());
await browser.close();
} finally {
await session.close();
client.close();
}The flow matches quickstart:
- SDK creates a cloud browser with API Key.
- Playwright connects to the remote browser through
connectUrl. - Code performs navigation and browser actions.
finallyreleases the session to avoid leftover cloud instances.
5. Enable downloads or replay storage
Downloads and replay storage are opt-in. Enable only the artifact type that the task needs.
const downloadSession = await client.sessions.create({
browserMode: 'normal',
downloads: { enabled: true },
});
const browser = await chromium.connectOverCDP(downloadSession.connectUrl);
const cdp = await browser.newBrowserCDPSession();
await cdp.send('Browser.setDownloadBehavior', {
behavior: 'allow',
downloadPath: '/config/Downloads',
eventsEnabled: true,
});
const replaySession = await client.sessions.create({
browserMode: 'normal',
recording: { persistent: true },
});Use client.sessions.downloads.list/get/archive after a download-enabled session produces files. Use the console session detail page after a recording-enabled session closes to inspect replay output.
6. How examples map to quickstart
| Example | Quickstart step | When to use it |
|---|---|---|
playwright-basic.ts | Create session, connect browser, visit page | First SDK smoke test |
session-management.ts | Create and list sessions | Manage parallel browsers |
session-downloads.ts | Retrieve downloaded files | Browser tasks that produce downloads |
context-basic.ts | Reuse browser context | Persist login state or browser data |
extension-basic.ts | Mount Chrome extension | Browser tasks that need extensions |
proxy-session.ts | Use custom proxy | Custom egress or authenticated proxy |
See Node.js Examples for details.
Lexmount Docs