Node.js SDK
Capabilities
Session, context, extension, download, logging, and error capabilities exposed by the Node.js SDK.
Core Features
Session Management
Create Session
// Basic creation
const session = await client.sessions.create();
// With browser mode
const session = await client.sessions.create({
browserMode: 'normal',
});
// With uploaded extensions
const session = await client.sessions.create({
browserMode: 'normal',
extensionIds: ['ext_11ff6ce20fb0'],
});
// With authenticated upstream proxy
const session = await client.sessions.create({
proxy: {
type: 'external',
server: 'http://192.168.1.1:8080',
username: 'user',
password: 'pass',
},
});
// Available browser modes:
// - 'normal': Chrome in standard browser container
// - 'light': lightweight browser modeCreate Session with Context
const context = await client.contexts.create({
metadata: { userId: '1001' },
});
const session = await client.sessions.create({
context: { id: context.id, mode: 'readWrite' },
});
// The SDK also accepts 'read_write', 'readOnly', and 'read_only'
// and normalizes them to the API payload format.List Sessions
const result = await client.sessions.list();
console.log(`Total: ${result.pagination.totalCount}`);
console.log(`Active: ${result.pagination.activeCount}`);
for (const session of result) {
console.log(`${session.id}: ${session.status}`);
}
const activeSessions = await client.sessions.list({ status: 'active' });
console.log(`Found ${activeSessions.length} active sessions`);Delete Session
await client.sessions.delete({ sessionId: 'session-id' });
// Or use the session object helper
await session.close();Session Timeout Behavior
- Session timeout is enforced server-side from the session's configured duration.
- If the timeout is reached but the platform has seen recent client CDP activity within the last 2 minutes, the session is kept alive temporarily instead of being deleted immediately.
- In practice, active
connectOverCDP, Playwright, Puppeteer, and raw DevTools traffic all count as CDP activity. - Once CDP activity stops for more than 2 minutes, the timed-out session becomes eligible for cleanup on the next timeout sweep.
Session Downloads
const session = await client.sessions.create({
downloads: { enabled: true },
});
const downloads = await client.sessions.downloads.list(session.id);
console.log(downloads.summary.count);
const fileBuffer = await client.sessions.downloads.get(session.id, 'download-id');
const archiveBuffer = await client.sessions.downloads.archive(session.id);
await client.sessions.downloads.delete(session.id);Persistent Replay
const session = await client.sessions.create({
recording: { persistent: true },
});Close the session after the task finishes, then inspect the replay artifact from the console session detail page.
Context Operations
const context = await client.contexts.create({
metadata: { owner: 'demo' },
});
const contexts = await client.contexts.list({
status: 'available',
limit: 20,
});
const details = await client.contexts.get(context.id);
console.log(details.status);
await client.contexts.forceRelease(context.id);
await client.contexts.delete(context.id);client.contexts.create(metadata=...)creates a server-side persistent browser profile.client.contexts.list(status=..., limit=...)lists available or locked contexts.client.contexts.get(contextId)reads one context.client.contexts.delete(contextId)deletes one context.client.contexts.forceRelease(contextId)clears a stuck lock as an emergency operation.
Extension Management
const extension = await client.extensions.upload('/absolute/path/to/extension.zip', {
name: 'demo-extension',
});
const extensions = await client.extensions.list({ limit: 10 });
for (const item of extensions) {
console.log(item.id, item.name);
}
const details = await client.extensions.get(extension.id);
await client.extensions.delete(extension.id);Error Handling
import {
APIError,
AuthenticationError,
ContextLockedError,
ContextNotFoundError,
NetworkError,
TimeoutError,
} from 'lexmount';
try {
await client.sessions.create({
context: { id: 'ctx_123', mode: 'readWrite' },
});
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Invalid credentials');
} else if (error instanceof ContextNotFoundError) {
console.error('Context not found');
} else if (error instanceof ContextLockedError) {
console.error(error.activeSessionId, error.retryAfter);
} else if (error instanceof TimeoutError || error instanceof NetworkError) {
console.error('Temporary connectivity issue');
} else if (error instanceof APIError) {
console.error(error.statusCode);
} else {
throw error;
}
}Logging
import { disableLogging, enableLogging, setLogLevel } from 'lexmount';
setLogLevel('DEBUG');
enableLogging('INFO');
disableLogging();Available levels:
DEBUGINFOWARNINGERRORCRITICALSILENT
API Reference Entry Points
This page maps the major public API entry points exposed by the package.
Client
Lexmount
Sessions
SessionsResourceSessionInfoSessionListResponsePaginationInfoSessionDownloadsResourceSessionDownloadInfoSessionDownloadsListResponseSessionDownloadsDeleteResponse
Contexts
ContextsResourceContextInfoContextListResponse
Extensions
ExtensionsResourceExtensionInfo
Exceptions
LexmountErrorAuthenticationErrorSessionNotFoundErrorContextNotFoundErrorContextLockedErrorAPIErrorNetworkErrorValidationErrorTimeoutError
Logging
LexmountLoggersetLogLevelenableLoggingdisableLogginggetLogger
Lexmount Docs