Node.js Examples
Explain Node.js examples by quickstart flow, use case, command, and expected result.
Start with playwright-basic.ts. It maps to the minimal quickstart loop: create session, connect over CDP, visit a page. Other examples extend that base flow.
Before running examples
npm install
npm run build
cp .env.example .env
# Fill LEXMOUNT_API_KEY and LEXMOUNT_PROJECT_ID
cd examples
npm installCommon environment variables:
LEXMOUNT_API_KEY=sk_...
LEXMOUNT_PROJECT_ID=project_...
LEXMOUNT_BASE_URL=https://api.lexmount.cn
LEXMOUNT_EXTENSION_PATH=/absolute/path/to/extension.zip
LEXMOUNT_PROXY_SERVER=http://host:port
LEXMOUNT_PROXY_USERNAME=optional
LEXMOUNT_PROXY_PASSWORD=optionalRecommended order
| Order | Example | Purpose |
|---|---|---|
| 1 | playwright-basic.ts | Create session, connect browser, visit page |
| 2 | session-management.ts | Create multiple sessions and list active sessions |
| 3 | session-downloads.ts | Retrieve downloaded files from the remote browser |
| 4 | context-basic.ts | Create and reuse browser context |
| 5 | context-list-get.ts | Inspect context list and detail |
| 6 | context-modes.ts | Understand readWrite / readOnly access |
| 7 | context-lock-handling.ts | Handle context lock conflicts |
| 8 | extension-basic.ts | Upload and mount Chrome extension |
| 9 | proxy-session.ts | Create session with custom proxy |
playwright-basic.ts: minimal browser loop
Run:
npm run playwright-basicIt creates a normal browser session, connects to the remote browser through connectUrl, opens https://example.com, and prints the title. Run this first for a new integration.
session-management.ts: manage sessions
Run:
npm run session-managementIt creates normal and light sessions, then lists active sessions. Use it to understand parallel browsers, pagination, and session metadata.
session-downloads.ts: retrieve downloads
Run:
npm run session-downloadsIt configures remote browser download behavior, triggers a download, then queries metadata and retrieves one file or all files as an archive.
Context examples
npm run context-basic
npm run context-list-get
npm run context-modes
npm run context-lock-handlingThese examples focus on reusing browser data:
context-basic.ts: create a context and mount it to a session.context-list-get.ts: inspect context metadata and status.context-modes.ts: show read-write and read-only access.context-lock-handling.ts: handle lock errors and retry metadata.
extension-basic.ts: extension support
Run:
npm run extension-basicAfter setting LEXMOUNT_EXTENSION_PATH, the script uploads an extension zip and mounts it with extensionIds when creating a session.
proxy-session.ts: custom proxy
Run:
npm run proxy-sessionAfter setting proxy environment variables, the script creates a proxied remote browser and verifies that browser traffic uses the proxy.
Troubleshooting
- If session creation fails, check API Key, Project ID, and project quota.
- If Playwright cannot connect, print
session.connectUrland confirm the session was not closed early. - If a context is locked, inspect
activeSessionIdandretryAfter, then retry after the active session releases it.
Lexmount Docs