Implementation:Microsoft Playwright Client Video
| Knowledge Sources | |
|---|---|
| Domains | Browser Automation, Video Recording |
| Last Updated | 2026-02-12 00:00 GMT |
Overview
Concrete tool for managing video recordings of browser page sessions provided by the Playwright library.
Description
The Video class implements the api.Video interface and manages video recording for a browser page. It wraps an underlying Artifact instance that represents the recorded video file. The class tracks whether the connection is remote (which affects path availability) and provides methods to:
- start(): Begin video recording with optional size configuration, receiving an Artifact from the server.
- stop(): Stop recording and optionally save the video to a specified path.
- path(): Get the local file path of the recording (throws if remote or not started).
- saveAs(): Save the recording to a specified path (throws if not started).
- delete(): Delete the recorded video file.
Usage
Use the Video class to record browser sessions for debugging, test evidence, or documentation. Access it via page.video(). Video recording can also be configured automatically through BrowserContextOptions.recordVideo.
Code Reference
Source Location
- Repository: Microsoft_Playwright
- File:
packages/playwright-core/src/client/video.ts
Signature
export class Video implements api.Video {
constructor(page: Page, connection: Connection, artifact: Artifact | undefined);
async start(options?: { size?: { width: number; height: number } }): Promise<void>;
async stop(options?: { path?: string }): Promise<void>;
async path(): Promise<string>;
async saveAs(path: string): Promise<void>;
async delete(): Promise<void>;
}
Import
import { Video } from 'playwright-core/src/client/video';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| page | Page |
Yes | The page to record video for |
| connection | Connection |
Yes | The connection instance (used to determine remote status) |
| artifact | undefined | No | Pre-existing artifact if recording was already started |
| options.size (start) | { width: number; height: number } |
No | Video recording dimensions |
| options.path (stop) | string |
No | Path to save the video to upon stopping |
| path (saveAs) | string |
Yes | Destination path for saving the recorded video |
Outputs
| Name | Type | Description |
|---|---|---|
| path() | Promise<string> |
The local file path of the recorded video (throws if remote or not started) |
| saveAs() | Promise<void> |
Saves the video to the specified path |
| delete() | Promise<void> |
Deletes the recorded video file |
Usage Examples
// Record video via context options
const context = await browser.newContext({
recordVideo: { dir: '/tmp/videos', size: { width: 1280, height: 720 } },
});
const page = await context.newPage();
// Perform actions
await page.goto('https://example.com');
await page.click('button');
// Save the video
const videoPath = await page.video().path();
console.log('Video saved at:', videoPath);
// Or save to a custom path
await page.video().saveAs('/tmp/test-recording.webm');
// Clean up
await page.video().delete();
await context.close();