🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# class:dialog ### class: Dialog v0.9.0 [Dialog](#?product=Puppeteer&version=v1.11.0&show=api-class-dialog "Dialog") 对象通过 ['dialog'](#?product=Puppeteer&version=v1.11.0&show=api-event-dialog) 事件的页面分发。 一个使用 `Dialog` 类的例子: ``` const puppeteer = require('puppeteer');puppeteer.launch().then(async browser => { 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 - [dialog.accept(\[promptText\])](#?product=Puppeteer&version=v1.11.0&show=api-dialogacceptprompttext)v0.9.0 - [dialog.defaultValue()](#?product=Puppeteer&version=v1.11.0&show=api-dialogdefaultvalue)v0.9.0 - [dialog.dismiss()](#?product=Puppeteer&version=v1.11.0&show=api-dialogdismiss)v0.9.0 - [dialog.message()](#?product=Puppeteer&version=v1.11.0&show=api-dialogmessage)v0.9.0 - [dialog.type()](#?product=Puppeteer&version=v1.11.0&show=api-dialogtype)v0.9.0 ### Methods #### dialog.accept(\[promptText\])v0.9.0 - `promptText` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 提示中输入的文本。 如果对话框的`类型`不提示,不会产生任何影响。 - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the dialog has been accepted. #### dialog.defaultValue()v0.9.0 - returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 如果对话框出现提示,则返回默认提示值。 否则,返回空字符串。 #### dialog.dismiss()v0.9.0 - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Promise which resolves when the dialog has been dismissed. #### dialog.message()v0.9.0 - returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 显示在对话框中的信息。 #### dialog.type()v0.9.0 - returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 对话框类型,可以是 `alert` ,`beforeunload` ,`confirm` 或 `prompt` 中的一个。 ![](images/pptr.png) puppeteer.js中文网|class:dialog puppeteer.js中文文档, puppeteer chrome, puppeteer firefox, puppeteer api 中文文档 puppeteer.js中文网包含了Puppeteer中文文档,最新资讯,应用案例等。Puppeteer 是一个 Node 库,它提供了一个高级 API 来通过 DevTools 协议控制 Chromium 或 Chrome。