Skip to Content

Browser

TL;DR

The browser service provides headless browser automation on remote machines with the same capabilities API as the Python SDK. Create sessions with configurable viewports and user agents, navigate pages, interact with DOM elements (click, type, select), take full-page or element screenshots, capture network traffic, and manage cookies. All operations run on the remote machine.

Headless browser automation on remote machines. Navigate, interact with DOM, take screenshots, and capture network traffic.

How do I create a browser session?

import { CMDOPClient } from '@cmdop/node'; // Connect to the remote machine via cloud relay const client = await CMDOPClient.remote({ apiKey: 'cmdop_xxx' }); // Create a headless browser session on the target machine const session = await client.browser.createSession({ machine: 'my-server', });

Session Options

// Create a session with custom viewport, user agent, and headless mode const session = await client.browser.createSession({ machine: 'my-server', viewport: { width: 1920, height: 1080 }, // Full HD viewport userAgent: 'custom-agent', // Override the default user agent headless: true, // Run without a visible browser window });

How do I navigate to pages?

// Navigate to a URL and wait for the page to load await session.navigate('https://example.com'); // Navigate and wait until a specific element appears in the DOM await session.navigate('https://example.com', { waitFor: '#content', }); // Browser history navigation await session.back(); await session.forward(); // Get the current page URL const url = await session.currentUrl();

How do I interact with DOM elements?

Click

// Click an element by CSS selector await session.click('#login-button'); await session.click('button[type="submit"]');

Type Text

// Type text into an input field identified by CSS selector await session.type('#email', '[email protected]'); // Type with clear:true to empty the field before typing await session.type('#password', 'secret', { clear: true });

Select

// Select an option from a dropdown by value await session.select('#country', 'US');

Get Text

// Extract the inner text or HTML content of an element const text = await session.getText('#result'); const html = await session.getHtml('#content');

Evaluate JavaScript

// Execute arbitrary JavaScript in the browser context and return the result const title = await session.evaluate('document.title');

How do I take screenshots?

// Capture a full-page screenshot as a buffer const screenshot = await session.screenshot(); // Capture only a specific element by CSS selector const elementShot = await session.screenshot({ selector: '#chart', }); // Save the screenshot directly to a file on the remote machine await session.screenshot({ path: '/tmp/screenshot.png' });

How do I capture network traffic?

// Get all HTTP requests made by the page const requests = await session.network.getRequests(); // Filter requests by a URL substring pattern const apiCalls = await session.network.getRequests({ urlPattern: '/api/', }); // Get the full response body for a specific request by its ID const response = await session.network.getResponse(requestId);

How do I manage cookies?

// Get all cookies for the current session const cookies = await session.cookies.getAll(); // Set a cookie with name, value, and domain await session.cookies.set({ name: 'session', value: 'abc123', domain: 'example.com', }); // Clear all cookies from the session await session.cookies.clear();

How do I close a browser session?

// Close the browser session and release remote resources await session.close();

What parameters do the browser methods accept?

createSession(options)

ParameterTypeDescription
options.machinestringTarget machine
options.viewport{ width: number; height: number }Viewport size
options.userAgentstringCustom user agent
options.headlessbooleanHeadless mode (default: true)
ParameterTypeDescription
urlstringURL to navigate to
options.waitForstringCSS selector to wait for
options.timeoutnumberNavigation timeout in ms
Last updated on