For AI agents: a documentation index is available at /llms.txt
Skip to main content

Record a Browser Session

Capture a video recording of a browser session — navigations, clicks, and interactions — as a .webm file using the Browserless recording API.

Prerequisites

Steps

Recording uses CDP commands Browserless.startRecording and Browserless.stopRecording. Three parameters are required in the WebSocket URL: headless=false (the recording extension captures a visible window), stealth (recording is not available on the standard /chrome route), and record=true. The video dimensions match the viewport when recording starts — set it before calling startRecording.

View Full Code on GitHub

1. Install dependencies

npm install puppeteer-core

2. Connect, record, and save

import fs from 'fs';
import puppeteer from 'puppeteer-core';

const browser = await puppeteer.connect({
browserWSEndpoint:
'wss://production-sfo.browserless.io?token=YOUR_API_TOKEN_HERE&headless=false&stealth&record=true',
});

try {
const page = await browser.newPage();

// Set viewport before starting — dimensions are fixed for the entire recording.
await page.setViewport({ width: 1280, height: 720 });

const cdp = await page.createCDPSession();
await cdp.send('Browserless.startRecording');

await page.goto('https://example.com', { waitUntil: 'networkidle2' });
await new Promise(r => setTimeout(r, 2000));
await page.goto('https://example.com/about', { waitUntil: 'networkidle2' });
await new Promise(r => setTimeout(r, 2000));

// base64 encoding is required — CDP can't transfer raw binary over its text protocol.
const { value } = await cdp.send('Browserless.stopRecording', { encoding: 'base64' });

fs.writeFileSync('recording.webm', Buffer.from(value, 'base64'));
console.log('Recording saved to recording.webm');
} finally {
// Always close to release the session even on error.
await browser.close();
}

3. Check the output

Run with node record.mjs. The file recording.webm contains the full browser session video.

Notes

  • The video is encoded as WebM (VP8). Convert to MP4 with ffmpeg -i recording.webm recording.mp4 if needed.
  • Do not change the viewport size after calling startRecording — the dimensions are fixed when recording begins.
  • For DOM-based session replay (not video), use replay=true in the connection URL instead — recordings are uploaded to the Browserless dashboard automatically.

Next steps