跳到主要内容
版本:2.0.0

Puppeteer API

puppeteer 命名空间提供了浏览器自动化控制和网页渲染功能,基于 Google Puppeteer。

命名空间

declare namespace puppeteer { ... }

方法

isRunning

检查浏览器是否正在运行。

function isRunning(): boolean;

installed

获取已安装的浏览器列表。

function installed(): InstalledBrowser[];

start

启动浏览器。

function start(browser: SupportedBrowser): Promise<void>;

close

关闭浏览器。

function close(): Promise<void>;

restart

重启浏览器。

function restart(): Promise<void>;

browser

获取浏览器实例 (IBrowser)。

function browser(): IBrowser | null;

renderHtml

将HTML字符串渲染为图片。

function renderHtml(html: string, timeoutSeconds?: number, width?: number | null, height?: number | null, navigation?: WaitUntilNavigation): Promise<string>;
  • 参数:
    • html: HTML内容字符串
    • timeoutSeconds: 超时时间(秒),默认20
    • width: 图片宽度
    • height: 图片高度
    • navigation: 等待导航完成的条件
  • 返回: 图片的Base64编码字符串

renderUrl

将URL渲染为图片。

function renderUrl(url: string, timeoutSeconds?: number, width?: number | null, height?: number | null, navigation?: WaitUntilNavigation): Promise<string>;
  • 参数:
    • url: 目标URL
    • timeoutSeconds: 超时时间(秒),默认20
    • width: 图片宽度
    • height: 图片高度
    • navigation: 等待导航完成的条件
  • 返回: 图片的Base64编码字符串

遇到麻烦了?

我们提供有偿代安装服务,解决您的环境配置烦恼。

了解详情