Quick Start
Install the SDK, configure credentials, and connect with Playwright.
This page follows the repository README and example scripts from lexmount-js-sdk, while keeping the structure aligned with the Python SDK documentation set.
Repository Setup
If you want to run the example code from the SDK repository, follow these steps:
1. Install Example Dependencies
git clone <repository-url>
cd lexmount-js-sdk/examples
npm install2. Configure Environment Variables
Create a .env file in the project root directory:
LEXMOUNT_API_KEY=your-api-key-here
LEXMOUNT_PROJECT_ID=your-project-id-here
# Optional
LEXMOUNT_BASE_URL=https://api.lexmount.cn3. Run Examples
npm run build
cd examples
npm run playwright-basic
npm run session-management
npm run context-basicBasic Usage
import { Lexmount } from 'lexmount';
const client = new Lexmount({
apiKey: process.env.LEXMOUNT_API_KEY,
projectId: process.env.LEXMOUNT_PROJECT_ID,
});
const session = await client.sessions.create();
console.log(`Session ID: ${session.id}`);
console.log(`Connect URL: ${session.connectUrl}`);
await session.close();
client.close();Using Environment Variables
import { Lexmount } from 'lexmount';
const client = new Lexmount();
const session = await client.sessions.create({ browserMode: 'normal' });
console.log(session.id);
await session.close();
client.close();Integration with Playwright
import { chromium } from 'playwright';
import { Lexmount } from 'lexmount';
const client = new Lexmount();
const session = await client.sessions.create();
const browser = await chromium.connectOverCDP(session.connectUrl);
const context = browser.contexts()[0];
const page = context.pages()[0] ?? (await context.newPage());
await page.goto('https://example.com');
console.log(await page.title());
await browser.close();
await session.close();
client.close();Constructor Notes
Configuration
import { Lexmount } from 'lexmount';
const client = new Lexmount({
apiKey: 'your-api-key',
projectId: 'your-project-id',
baseUrl: 'https://api.lexmount.cn',
timeout: 60_000,
logLevel: 'INFO',
});Creating a Session
const session = await client.sessions.create({
browserMode: 'normal',
});
console.log(session.id);
console.log(session.connectUrl);Session timeout is managed by the platform. If your session has already reached its configured timeout but the platform still sees CDP traffic from the client within the last 2 minutes, cleanup is deferred until that activity window expires.
Listing Sessions
const result = await client.sessions.list({ status: 'active' });
console.log(result.pagination.totalCount);
for (const session of result) {
console.log(`${session.id}: ${session.status}`);
}Error Handling
import {
AuthenticationError,
Lexmount,
NetworkError,
TimeoutError,
} from 'lexmount';
try {
const client = new Lexmount();
await client.sessions.create();
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Invalid credentials');
} else if (error instanceof TimeoutError) {
console.error('Request timed out');
} else if (error instanceof NetworkError) {
console.error('Network connection failed');
} else {
throw error;
}
}Logging
import { setLogLevel } from 'lexmount';
setLogLevel('DEBUG');
Lexmount Docs