Skip to main content
Version: 22.9.0

Dialog 类

¥Dialog class

对话框实例由 通过 dialog 事件调度。

¥Dialog instances are dispatched by the Page via the dialog event.

签名:

¥Signature:

export declare abstract class Dialog

备注

¥Remarks

此类的构造函数被标记为内部构造函数。第三方代码不应直接调用构造函数或创建扩展 Dialog 类的子类。

¥The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the Dialog class.

示例

¥Example

import puppeteer from 'puppeteer';

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
page.on('dialog', async dialog => {
console.log(dialog.message());
await dialog.dismiss();
await browser.close();
});
page.evaluate(() => alert('1'));
})();

方法

¥Methods

方法

修饰符

描述

accept(promptText)

当对话被接受时解决的 promise。

defaultValue()

提示的默认值,如果对话框不是 prompt,则为空字符串。

dismiss()

一旦对话框被解除,就会解决的 promise

message()

对话框中显示的消息。

type()

对话框的类型。