Logo of LexmountLexmount Docs
Logo of LexmountLexmount Docs
Homepage

Introduction

Documentation Overview
Node.js SDKNode.js SDK Quick StartCapabilitiesNode.js Examples
X (Twitter)
Node.js SDK

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 chromium

If you are running examples from the SDK repository:

npm install
npm run build
cd examples
npm install

2. Configure environment variables

LEXMOUNT_API_KEY=sk_...
LEXMOUNT_PROJECT_ID=project_...
LEXMOUNT_BASE_URL=https://api.lexmount.cn

Get 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:

  1. SDK creates a cloud browser with API Key.
  2. Playwright connects to the remote browser through connectUrl.
  3. Code performs navigation and browser actions.
  4. finally releases 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

ExampleQuickstart stepWhen to use it
playwright-basic.tsCreate session, connect browser, visit pageFirst SDK smoke test
session-management.tsCreate and list sessionsManage parallel browsers
session-downloads.tsRetrieve downloaded filesBrowser tasks that produce downloads
context-basic.tsReuse browser contextPersist login state or browser data
extension-basic.tsMount Chrome extensionBrowser tasks that need extensions
proxy-session.tsUse custom proxyCustom egress or authenticated proxy

See Node.js Examples for details.

Node.js SDK

Import-ready Lexmount Node.js SDK documentation for Lex Home.

Capabilities

Session, context, extension, download, logging, and error capabilities exposed by the Node.js SDK.

Table of Contents

1. Install dependencies
2. Configure environment variables
3. Create a session
4. Connect with Playwright
5. Enable downloads or replay storage
6. How examples map to quickstart