Skip to main content
Version: v2

Screencast API

info

This information applies for users that have dedicated worker(s) in the capacity-based plan.

The screencast API allows for generating webm video files on demand of your Puppeteer or Playwright scripts. The API supports recording audio.

The resulting video's dimensions are inherited by the width and height of the browser. You can change this very easily by calling page.setViewport with your dimensions in your scripts as well as setting --window-size in the URL.

Usage

This API works over CDP, thus you can use with with Puppeteer, Playwright, ChromeCDP or any other library that support CDP connections. You must add record=true to your connection string in order to use this API.

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://chrome.browserless.io?token=${token}&headless=false&stealth&record=true`;
const browser = await puppeteer.connect({ browserWSEndpoint: wsEndpoint });
const page = await browser.newPage();
await page.goto("https://browserless.io");

// The magic happens here
const cdp = await page.createCDPSession();
await cdp.send("Browserless.startRecording");
await sleep(15000);
const response = await cdp.send("Browserless.stopRecording");
// ☝️ The response is a string containing a valid webm file

const file = Buffer.from(response.value, "binary");
await fs.promises.writeFile("./recording.webm", file);

await browser.close();