Skip to main content
Version: 24.17.0

Page.screencast() 方法

¥Page.screencast() method

捕获此 page 的截屏视频。

¥Captures a screencast of this page.

签名

¥Signature

class Page {
screencast(options?: Readonly<ScreencastOptions>): Promise<ScreenRecorder>;
}

参数

¥Parameters

范围

类型

描述

options

只读<ScreencastOptions>

(可选的)配置截屏行为。

Returns:

Promise<ScreenRecorder>

备注

¥Remarks

默认情况下,所有录制都将是使用 VP9 视频编解码器的 WebM 格式,帧速率为 30 FPS。

¥By default, all recordings will be WebM format using the VP9 video codec, with a frame rate of 30 FPS.

你的系统上必须安装有 ffmpeg

¥You must have ffmpeg installed on your system.

示例

¥Example

录制 page

¥Recording a page:

import puppeteer from 'puppeteer';

// Launch a browser
const browser = await puppeteer.launch();

// Create a new page
const page = await browser.newPage();

// Go to your site.
await page.goto("https://www.example.com");

// Start recording.
const recorder = await page.screencast({path: 'recording.webm'});

// Do something.

// Stop recording.
await recorder.stop();

browser.close();