Node.js Quick Start
Create Chromium and Moli sessions and connect to Chromium with Playwright.
Prepare credentials first
Create an API Key and copy its Project ID from Settings → API Keys. You can verify the same flow in the console quick start before running code.
1. Install
Use Node.js 20 or later for these pinned Playwright dependencies.
npm install lexmount@0.5.17 playwright@1.63.0 dotenv2. Configure credentials
export LEXMOUNT_API_KEY='<your-api-key>'
export LEXMOUNT_PROJECT_ID='<your-project-id>'
# Optional; defaults to the CN API
export LEXMOUNT_BASE_URL=https://api.lexmount.cn3. Create and control Chromium
Save the following as example.mjs and run node example.mjs.
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();
}
}
}Always close the session in finally so a browser is not left running after an exception.
4. Create Moli
Moli is the product name for the stable SDK/API value light:
const session = await client.sessions.create({
browserMode: "light",
enableLightmountLayout: true,
enableLightmountResource: true,
});Use Moli for lightweight agent browsing and content-oriented tasks. Persistent replay is always disabled for Moli. Use Chromium when a task depends on the full persistent-browser feature set.
5. Know the defaults
| Behavior | Current default |
|---|---|
| Session create path | Async create, polling until active |
| Activation timeout | 600 seconds |
| Stored downloads | Enabled unless downloads: { enabled: false } |
| Chromium persistent replay | Enabled by the current platform unless explicitly disabled |
| Moli persistent replay | Always disabled |
| Region | Default catalog region when available; otherwise the configured base URL |
Explicitly disable artifacts that the task does not need:
const session = await client.sessions.create({
browserMode: "normal",
downloads: { enabled: false },
recording: { persistent: false },
});6. Select a region
const client = new Lexmount({ region: "<region-id>" });
console.log(await client.regionInfo());
console.log(await client.catalogInfo());
client.close();If catalog lookup or host probing is unavailable, the SDK falls back to LEXMOUNT_BASE_URL.
Troubleshooting
- Authentication error: confirm the API Key and Project ID come from the same project.
- Create timeout: inspect the exception and console session list before retrying; async create may already have reserved a session ID.
- View works but Playwright does not connect: confirm the session is active and your network can reach
session.connectUrl. - Resources remain active: close both the browser connection and session in
finally.
Continue with Node.js Capabilities or run a script from Node.js Examples.
