屏幕录制
用于从页面捕获屏幕录像帧的接口。
🌐 Interface for capturing screencast frames from a page.
方法
🌐 Methods
hideActions
Added in: v1.59移除动作装饰。
🌐 Removes action decorations.
用法
await screencast.hideActions();
返回
hideOverlays
Added in: v1.59隐藏覆盖层而不移除它们。
🌐 Hides overlays without removing them.
用法
await screencast.hideOverlays();
返回
showActions
Added in: v1.59在被交互的元素上启用可视注释。返回一个一次性对象,当被释放时会停止显示操作。
🌐 Enables visual annotations on interacted elements. Returns a disposable that stops showing actions when disposed.
用法
await screencast.showActions();
await screencast.showActions(options);
参数
optionsObject (optional)
返回
showChapter
Added in: v1.59显示带有标题和可选描述的章节覆盖,居中显示在页面上,并带有模糊背景。适用于视频录制的解说。覆盖将在指定时间后或2000毫秒后移除。
🌐 Shows a chapter overlay with a title and optional description, centered on the page with a blurred backdrop. Useful for narrating video recordings. The overlay is removed after the specified duration, or 2000ms.
用法
await screencast.showChapter(title);
await screencast.showChapter(title, options);
参数
-
在覆盖层中高亮的标题文本。
-
optionsObject (optional)
返回
showOverlay
Added in: v1.59添加一个带有指定 HTML 内容的覆盖层。该覆盖层会显示在页面上方,直到被移除。返回一个可释放对象,释放时会移除覆盖层。
🌐 Adds an overlay with the given HTML content. The overlay is displayed on top of the page until removed. Returns a disposable that removes the overlay when disposed.
用法
await screencast.showOverlay(html);
await screencast.showOverlay(html, options);
参数
-
覆盖层的 HTML 内容。
-
optionsObject (optional)
返回
showOverlays
Added in: v1.59显示叠加层。
🌐 Shows overlays.
用法
await screencast.showOverlays();
返回
start
Added in: v1.59开始屏幕录制。当提供path时,它会将视频录制保存到指定的文件中。当提供onFrame时,会将JPEG编码的帧传递给回调。两者可以同时使用。
🌐 Starts the screencast. When path is provided, it saves video recording to the specified file. When onFrame is provided, delivers JPEG-encoded frames to the callback. Both can be used together.
用法
// Record video
await page.screencast.start({ path: 'video.webm', size: { width: 1280, height: 800 } });
// ... perform actions ...
await page.screencast.stop();
// Capture frames
await page.screencast.start({
onFrame: ({ data }) => console.log(`frame size: ${data.length}`),
size: { width: 800, height: 600 },
});
// ... perform actions ...
await page.screencast.stop();
参数
optionsObject (optional)
返回
stop
Added in: v1.59如果正在进行屏幕录制和视频录制,则停止它们。如果正在录制视频,会将其保存到screencast.start()中指定的路径。
🌐 Stops the screencast and video recording if active. If a video was being recorded, saves it to the path specified in screencast.start().
用法
await screencast.stop();
返回