Skip to main content
Version: 23.8.0

Page.screenshot() 方法

¥Page.screenshot() method

screenshot():Promise<string>

捕获此 page 的屏幕截图。

¥Captures a screenshot of this page.

签名

¥Signature

class Page {
screenshot(
options: Readonly<ScreenshotOptions> & {
encoding: 'base64';
},
): Promise<string>;
}

参数

¥Parameters

范围

类型

描述

options

Readonly<ScreenshotOptions> & { encoding: 'base64'; }

配置屏幕截图行为。

Returns:

Promise<string>

备注

¥Remarks

BrowserContext 中截屏时,以下方法将自动等待截屏完成,以防止干扰截屏过程:BrowserContext.newPage(), Browser.newPage(), Page.close().

¥While a screenshot is being taken in a BrowserContext, the following methods will automatically wait for the screenshot to finish to prevent interference with the screenshot process: BrowserContext.newPage(), Browser.newPage(), Page.close().

调用 Page.bringToFront() 不会等待现有的屏幕截图操作。

¥Calling Page.bringToFront() will not wait for existing screenshot operations.

screenshot():Promise<Uint8Array>

签名

¥Signature

class Page {
screenshot(options?: Readonly<ScreenshotOptions>): Promise<Uint8Array>;
}

参数

¥Parameters

范围

类型

描述

options

只读<ScreenshotOptions>

(可选的)

Returns:

Promise<Uint8Array>