Skip to main content

Screencast API

info

Screencasting (Screen Recording) is only available on paid plans.

The Screencast API enables on-demand generation of WebM video files from your Puppeteer or Playwright automation scripts. The API supports both video and audio recording, making it ideal for creating comprehensive session recordings, debugging automation workflows, and capturing user interactions. This feature is not to be confused with the Session Replay feature, which captures DOM events and is viewable in your dashboard with automatic recording.

Key Features

The Screencast API provides high-quality WebM output with efficient compression, audio recording support automatically captured with video, flexible video dimensions inherited from browser viewport settings, CDP-based control for precise recording start/stop timing, and cross-library compatibility with Puppeteer, Playwright, and other CDP-supporting tools.

Connection Requirements

You must add record=true to your connection string to enable the Screencast API. This parameter loads the screencast extension that handles video capture.

Video Dimensions Configuration

The resulting WebM dimensions are inherited from the page viewport size at the moment recording starts. For example, if you run await page.setViewport({ width: 2048, height: 720 }); before Browserless.startRecording, the resulting video will be 2048x720 px.

You can customize viewport dimensions in several ways:

  • Puppeteer: Use page.setViewport({ width: 1280, height: 720 })
  • URL Parameters: Add --window-size=1280,720 and headless=false to your connection string
  • Launch Arguments: Configure viewport in browser launch options
CDP Fallback for Viewport Sizing

If your automation library does not expose a page.setViewport or page.setViewportSize method, you can set dimensions directly with the CDP Emulation.setDeviceMetricsOverride method. Most libraries use this CDP command under the hood when updating viewport size. See the DevTools Protocol reference: https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setDeviceMetricsOverride.

Avoid Resizing During Recording

Avoid changing the viewport size while recording is in progress. Mid-recording viewport changes can distort rendered content and produce a visibly stretched or otherwise unusual recording.

Basic Usage

This API works over CDP, thus you can use it with Puppeteer, Playwright, ChromeCDP or any other library that support CDP connections.

The following examples demonstrate how to implement screencasting across different automation libraries. Each example shows the complete workflow: connecting to Browserless, starting a recording session, performing automation tasks, stopping the recording, and saving the resulting WebM video file to disk.

import fs from "fs";
import puppeteer from "puppeteer-core";

const sleep = (ms) => new Promise((res) => setTimeout(res, ms));
const token = "YOUR_API_TOKEN_HERE";

const wsEndpoint = `wss://production-sfo.browserless.io?token=${token}&headless=false&stealth&record=true`;
const browser = await puppeteer.connect({ browserWSEndpoint: wsEndpoint });
const page = await browser.newPage();

// Set custom viewport for recording dimensions
await page.setViewport({ width: 1280, height: 720 });
await page.goto("https://browserless.io");

// Start recording session
const cdp = await page.createCDPSession();
await cdp.send("Browserless.startRecording");

// Perform your automation actions here
await sleep(15000);

// Stop recording and save
const response = await cdp.send("Browserless.stopRecording");
const file = Buffer.from(response.value, "binary");
await fs.promises.writeFile("./recording.webm", file);

await browser.close();

Next Steps

Ready to explore more BaaS features? Continue your journey with these essential capabilities: