Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/src/api/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,10 @@ When set to `minimal`, only record information necessary for routing from HAR. T
- `duration` ?<[float]> How long each annotation is displayed in milliseconds. Defaults to `500`.
- `position` ?<[AnnotatePosition]<"top-left"|"top"|"top-right"|"bottom-left"|"bottom"|"bottom-right">> Position of the action title overlay. Defaults to `"top-right"`.
- `fontSize` ?<[int]> Font size of the action title in pixels. Defaults to `24`.
- `ffmpegExecutable` ?<[path]> Path to a system ffmpeg binary to use instead of the one bundled with Playwright. The bundled binary ships with VP8 support only — provide a system ffmpeg to enable VP9, H264, AV1 and other encoders.
- `ffmpegOptions` ?<[string]> Full ffmpeg command line (everything between the executable and the output file). When set, replaces Playwright's default encoder pipeline entirely. You are responsible for reading raw frames from stdin (`-f image2pipe -c:v mjpeg -i pipe:0`), for the `-vf` filter that resizes them to `size`, and for setting `-r <fps>` before `-i pipe:0` to match the `fps` field — without it ffmpeg defaults image2pipe to 25 fps and your video will play at the wrong speed when `fps` differs.
- `fps` ?<[int]> Frame rate used by the internal frame-repetition algorithm that fills gaps between browser screencast events. When `ffmpegOptions` is not set, it is also passed to ffmpeg as `-r`. When you provide `ffmpegOptions`, set `-r <fps>` yourself to match it. Defaults to `25`.
- `outputExtension` ?<[string]> Extension of the output file, without leading `.`. Defaults to `webm`. Use `mp4` or another container supported by your ffmpeg binary to record in a different format.

Enables video recording for all pages into `recordVideo.dir` directory. If not specified videos are not recorded. Make
sure to await [`method: BrowserContext.close`] for videos to be saved.
Expand All @@ -851,6 +855,34 @@ Dimensions of the recorded videos. If not specified the size will be equal to `v
scaled down to fit into 800x800. If `viewport` is not configured explicitly the video size defaults to 800x450.
Actual picture of each page will be scaled down if necessary to fit the specified size.

## context-option-recordvideo-ffmpegexecutable
* langs: csharp, java, python
- alias-python: record_video_ffmpeg_executable
- `recordVideoFfmpegExecutable` <[path]>

Path to a system ffmpeg binary to use instead of the one bundled with Playwright. The bundled binary ships with VP8 support only — provide a system ffmpeg to enable VP9, H264, AV1 and other encoders.

## context-option-recordvideo-ffmpegoptions
* langs: csharp, java, python
- alias-python: record_video_ffmpeg_options
- `recordVideoFfmpegOptions` <[string]>

Full ffmpeg command line (everything between the executable and the output file). When set, replaces Playwright's default encoder pipeline entirely. You are responsible for reading raw frames from stdin (`-f image2pipe -c:v mjpeg -i pipe:0`), for the `-vf` filter that resizes them to `recordVideoSize`, and for setting `-r <fps>` before `-i pipe:0` to match `recordVideoFps` — without it ffmpeg defaults image2pipe to 25 fps and your video will play at the wrong speed when `recordVideoFps` differs.

## context-option-recordvideo-fps
* langs: csharp, java, python
- alias-python: record_video_fps
- `recordVideoFps` <[int]>

Frame rate used by the internal frame-repetition algorithm that fills gaps between browser screencast events. When `recordVideoFfmpegOptions` is not set, it is also passed to ffmpeg as `-r`. When you provide `recordVideoFfmpegOptions`, set `-r <fps>` yourself to match it. Defaults to `25`.

## context-option-recordvideo-outputextension
* langs: csharp, java, python
- alias-python: record_video_output_extension
- `recordVideoOutputExtension` <[string]>

Extension of the output file, without leading `.`. Defaults to `webm`. Use `mp4` or another container supported by your ffmpeg binary to record in a different format.

## context-option-proxy
- `proxy` <[Object]>
* alias: Proxy
Expand Down Expand Up @@ -1075,6 +1107,10 @@ between the same pixel in compared images, between zero (strict) and one (lax),
- %%-context-option-recordvideo-%%
- %%-context-option-recordvideo-dir-%%
- %%-context-option-recordvideo-size-%%
- %%-context-option-recordvideo-ffmpegexecutable-%%
- %%-context-option-recordvideo-ffmpegoptions-%%
- %%-context-option-recordvideo-fps-%%
- %%-context-option-recordvideo-outputextension-%%
- %%-context-option-strict-%%
- %%-context-option-service-worker-policy-%%

Expand Down
4 changes: 4 additions & 0 deletions docs/src/test-api/class-testoptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,10 @@ export default defineConfig({
- `level` ?<[TestAnnotationLevel]<"file"|"test"|"step">> Level of the detail to include about the current test.
- `position` ?<[AnnotatePosition]<"top-left"|"top"|"top-right"|"bottom-left"|"bottom"|"bottom-right">> Position of the test information overlay. Defaults to `"top-left"`.
- `fontSize` ?<[int]> Font size of the test information in pixels. Defaults to `14`.
- `ffmpegExecutable` ?<[string]> Path to a system ffmpeg binary to use instead of the one bundled with Playwright.
- `ffmpegOptions` ?<[string]> Full ffmpeg command line replacing Playwright's default encoder pipeline. See [`option: BrowserType.launchPersistentContext.recordVideo`] for the semantics.
- `fps` ?<[int]> Frame rate. Defaults to `25`.
- `outputExtension` ?<[string]> Output container extension without leading `.`. Defaults to `webm`.

Whether to record video for each test. Defaults to `'off'`.
* `'off'`: Do not record video.
Expand Down
140 changes: 140 additions & 0 deletions packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10499,6 +10499,34 @@ export interface Browser {
*/
fontSize?: number;
};

/**
* Path to a system ffmpeg binary to use instead of the one bundled with Playwright. The bundled binary ships with VP8
* support only — provide a system ffmpeg to enable VP9, H264, AV1 and other encoders.
*/
ffmpegExecutable?: string;

/**
* Full ffmpeg command line (everything between the executable and the output file). When set, replaces Playwright's
* default encoder pipeline entirely. You are responsible for reading raw frames from stdin (`-f image2pipe -c:v mjpeg
* -i pipe:0`), for the `-vf` filter that resizes them to `size`, and for setting `-r <fps>` before `-i pipe:0` to
* match the `fps` field — without it ffmpeg defaults image2pipe to 25 fps and your video will play at the wrong speed
* when `fps` differs.
*/
ffmpegOptions?: string;

/**
* Frame rate used by the internal frame-repetition algorithm that fills gaps between browser screencast events. When
* `ffmpegOptions` is not set, it is also passed to ffmpeg as `-r`. When you provide `ffmpegOptions`, set `-r <fps>`
* yourself to match it. Defaults to `25`.
*/
fps?: number;

/**
* Extension of the output file, without leading `.`. Defaults to `webm`. Use `mp4` or another container supported by
* your ffmpeg binary to record in a different format.
*/
outputExtension?: string;
};

/**
Expand Down Expand Up @@ -15947,6 +15975,34 @@ export interface BrowserType<Unused = {}> {
*/
fontSize?: number;
};

/**
* Path to a system ffmpeg binary to use instead of the one bundled with Playwright. The bundled binary ships with VP8
* support only — provide a system ffmpeg to enable VP9, H264, AV1 and other encoders.
*/
ffmpegExecutable?: string;

/**
* Full ffmpeg command line (everything between the executable and the output file). When set, replaces Playwright's
* default encoder pipeline entirely. You are responsible for reading raw frames from stdin (`-f image2pipe -c:v mjpeg
* -i pipe:0`), for the `-vf` filter that resizes them to `size`, and for setting `-r <fps>` before `-i pipe:0` to
* match the `fps` field — without it ffmpeg defaults image2pipe to 25 fps and your video will play at the wrong speed
* when `fps` differs.
*/
ffmpegOptions?: string;

/**
* Frame rate used by the internal frame-repetition algorithm that fills gaps between browser screencast events. When
* `ffmpegOptions` is not set, it is also passed to ffmpeg as `-r`. When you provide `ffmpegOptions`, set `-r <fps>`
* yourself to match it. Defaults to `25`.
*/
fps?: number;

/**
* Extension of the output file, without leading `.`. Defaults to `webm`. Use `mp4` or another container supported by
* your ffmpeg binary to record in a different format.
*/
outputExtension?: string;
};

/**
Expand Down Expand Up @@ -22518,6 +22574,34 @@ export interface Electron {
*/
fontSize?: number;
};

/**
* Path to a system ffmpeg binary to use instead of the one bundled with Playwright. The bundled binary ships with VP8
* support only — provide a system ffmpeg to enable VP9, H264, AV1 and other encoders.
*/
ffmpegExecutable?: string;

/**
* Full ffmpeg command line (everything between the executable and the output file). When set, replaces Playwright's
* default encoder pipeline entirely. You are responsible for reading raw frames from stdin (`-f image2pipe -c:v mjpeg
* -i pipe:0`), for the `-vf` filter that resizes them to `size`, and for setting `-r <fps>` before `-i pipe:0` to
* match the `fps` field — without it ffmpeg defaults image2pipe to 25 fps and your video will play at the wrong speed
* when `fps` differs.
*/
ffmpegOptions?: string;

/**
* Frame rate used by the internal frame-repetition algorithm that fills gaps between browser screencast events. When
* `ffmpegOptions` is not set, it is also passed to ffmpeg as `-r`. When you provide `ffmpegOptions`, set `-r <fps>`
* yourself to match it. Defaults to `25`.
*/
fps?: number;

/**
* Extension of the output file, without leading `.`. Defaults to `webm`. Use `mp4` or another container supported by
* your ffmpeg binary to record in a different format.
*/
outputExtension?: string;
};

/**
Expand Down Expand Up @@ -23206,6 +23290,34 @@ export interface AndroidDevice {
*/
fontSize?: number;
};

/**
* Path to a system ffmpeg binary to use instead of the one bundled with Playwright. The bundled binary ships with VP8
* support only — provide a system ffmpeg to enable VP9, H264, AV1 and other encoders.
*/
ffmpegExecutable?: string;

/**
* Full ffmpeg command line (everything between the executable and the output file). When set, replaces Playwright's
* default encoder pipeline entirely. You are responsible for reading raw frames from stdin (`-f image2pipe -c:v mjpeg
* -i pipe:0`), for the `-vf` filter that resizes them to `size`, and for setting `-r <fps>` before `-i pipe:0` to
* match the `fps` field — without it ffmpeg defaults image2pipe to 25 fps and your video will play at the wrong speed
* when `fps` differs.
*/
ffmpegOptions?: string;

/**
* Frame rate used by the internal frame-repetition algorithm that fills gaps between browser screencast events. When
* `ffmpegOptions` is not set, it is also passed to ffmpeg as `-r`. When you provide `ffmpegOptions`, set `-r <fps>`
* yourself to match it. Defaults to `25`.
*/
fps?: number;

/**
* Extension of the output file, without leading `.`. Defaults to `webm`. Use `mp4` or another container supported by
* your ffmpeg binary to record in a different format.
*/
outputExtension?: string;
};

/**
Expand Down Expand Up @@ -24386,6 +24498,34 @@ export interface BrowserContextOptions {
*/
fontSize?: number;
};

/**
* Path to a system ffmpeg binary to use instead of the one bundled with Playwright. The bundled binary ships with VP8
* support only — provide a system ffmpeg to enable VP9, H264, AV1 and other encoders.
*/
ffmpegExecutable?: string;

/**
* Full ffmpeg command line (everything between the executable and the output file). When set, replaces Playwright's
* default encoder pipeline entirely. You are responsible for reading raw frames from stdin (`-f image2pipe -c:v mjpeg
* -i pipe:0`), for the `-vf` filter that resizes them to `size`, and for setting `-r <fps>` before `-i pipe:0` to
* match the `fps` field — without it ffmpeg defaults image2pipe to 25 fps and your video will play at the wrong speed
* when `fps` differs.
*/
ffmpegOptions?: string;

/**
* Frame rate used by the internal frame-repetition algorithm that fills gaps between browser screencast events. When
* `ffmpegOptions` is not set, it is also passed to ffmpeg as `-r`. When you provide `ffmpegOptions`, set `-r <fps>`
* yourself to match it. Defaults to `25`.
*/
fps?: number;

/**
* Extension of the output file, without leading `.`. Defaults to `webm`. Use `mp4` or another container supported by
* your ffmpeg binary to record in a different format.
*/
outputExtension?: string;
};

/**
Expand Down
10 changes: 7 additions & 3 deletions packages/playwright-core/src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,13 @@ async function prepareStorageState(platform: Platform, storageState: string | Se
export async function prepareBrowserContextParams(platform: Platform, options: BrowserContextOptions): Promise<channels.BrowserNewContextParams> {
if (options.extraHTTPHeaders)
network.validateHeaders(options.extraHTTPHeaders);
const { recordVideo, ...rest } = options;
const recordVideoForWire = recordVideo ? {
...recordVideo,
dir: recordVideo.dir ? platform.path().resolve(recordVideo.dir) : recordVideo.dir,
} : undefined;
const contextParams: channels.BrowserNewContextParams = {
...options,
...rest,
viewport: options.viewport === null ? undefined : options.viewport,
noDefaultViewport: options.viewport === null,
extraHTTPHeaders: options.extraHTTPHeaders ? headersObjectToArray(options.extraHTTPHeaders) : undefined,
Expand All @@ -557,9 +562,8 @@ export async function prepareBrowserContextParams(platform: Platform, options: B
contrast: options.contrast === null ? 'no-override' : options.contrast,
acceptDownloads: toAcceptDownloadsProtocol(options.acceptDownloads),
clientCertificates: await toClientCertificatesProtocol(platform, options.clientCertificates),
recordVideo: recordVideoForWire,
};
if (contextParams.recordVideo && contextParams.recordVideo.dir)
contextParams.recordVideo.dir = platform.path().resolve(contextParams.recordVideo.dir);
return contextParams;
}

Expand Down
20 changes: 20 additions & 0 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ scheme.AndroidDeviceLaunchBrowserParams = tObject({
fontSize: tOptional(tInt),
cursor: tOptional(tEnum(['none', 'pointer'])),
})),
ffmpegExecutable: tOptional(tString),
ffmpegOptions: tOptional(tString),
fps: tOptional(tInt),
outputExtension: tOptional(tString),
})),
strictSelectors: tOptional(tBoolean),
serviceWorkers: tOptional(tEnum(['allow', 'block'])),
Expand Down Expand Up @@ -494,6 +498,10 @@ scheme.BrowserNewContextParams = tObject({
fontSize: tOptional(tInt),
cursor: tOptional(tEnum(['none', 'pointer'])),
})),
ffmpegExecutable: tOptional(tString),
ffmpegOptions: tOptional(tString),
fps: tOptional(tInt),
outputExtension: tOptional(tString),
})),
strictSelectors: tOptional(tBoolean),
serviceWorkers: tOptional(tEnum(['allow', 'block'])),
Expand Down Expand Up @@ -571,6 +579,10 @@ scheme.BrowserNewContextForReuseParams = tObject({
fontSize: tOptional(tInt),
cursor: tOptional(tEnum(['none', 'pointer'])),
})),
ffmpegExecutable: tOptional(tString),
ffmpegOptions: tOptional(tString),
fps: tOptional(tInt),
outputExtension: tOptional(tString),
})),
strictSelectors: tOptional(tBoolean),
serviceWorkers: tOptional(tEnum(['allow', 'block'])),
Expand Down Expand Up @@ -670,6 +682,10 @@ scheme.BrowserContextInitializer = tObject({
fontSize: tOptional(tInt),
cursor: tOptional(tEnum(['none', 'pointer'])),
})),
ffmpegExecutable: tOptional(tString),
ffmpegOptions: tOptional(tString),
fps: tOptional(tInt),
outputExtension: tOptional(tString),
})),
strictSelectors: tOptional(tBoolean),
serviceWorkers: tOptional(tEnum(['allow', 'block'])),
Expand Down Expand Up @@ -1074,6 +1090,10 @@ scheme.BrowserTypeLaunchPersistentContextParams = tObject({
fontSize: tOptional(tInt),
cursor: tOptional(tEnum(['none', 'pointer'])),
})),
ffmpegExecutable: tOptional(tString),
ffmpegOptions: tOptional(tString),
fps: tOptional(tInt),
outputExtension: tOptional(tString),
})),
strictSelectors: tOptional(tBoolean),
serviceWorkers: tOptional(tEnum(['allow', 'block'])),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@ export class BrowserDispatcher extends Dispatcher<Browser, channels.BrowserChann
}

async newContext(params: channels.BrowserNewContextParams, progress: Progress): Promise<channels.BrowserNewContextResult> {
if (params.recordVideo && this._object.attribution.playwright.options.isServer)
if (params.recordVideo && this._object.attribution.playwright.options.isServer) {
params.recordVideo.dir = undefined;
// Same rationale as `dir`: a remote client must not be able to inject
// arbitrary ffmpeg arguments — or pick an arbitrary executable — on the
// server (it would allow arbitrary file reads/writes and process
// invocation via filters / inputs / external binaries).
params.recordVideo.ffmpegExecutable = undefined;
params.recordVideo.ffmpegOptions = undefined;
params.recordVideo.outputExtension = undefined;
}

if (!this._options.isolateContexts) {
const context = await this._object.newContext(progress, params);
Expand Down
Loading
Loading