Puppeteer 中文文档v25.8.0

Page.screenshot() 方法

screenshot(): Promise<string>

捕获此页面的截图。

签名

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

参数

参数

类型

说明

options

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

配置截图行为。

返回值:

Promise<string>

备注

当在浏览器上下文中截图时,以下方法会自动等待截图完成,以避免干扰截图过程:BrowserContext.newPage()Browser.newPage()Page.close()

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

screenshot(): Promise<Uint8Array>

签名

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

参数

参数

类型

说明

options

Readonly<ScreenshotOptions>

(可选)

返回值:

Promise<Uint8Array>