# 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` 中的一個。

puppeteer.js中文網|class:dialog
puppeteer.js中文文檔, puppeteer chrome, puppeteer firefox, puppeteer api 中文文檔
puppeteer.js中文網包含了Puppeteer中文文檔,最新資訊,應用案例等。Puppeteer 是一個 Node 庫,它提供了一個高級 API 來通過 DevTools 協議控制 Chromium 或 Chrome。
- Introduction
- 版本記錄
- 概要
- puppeteer-vs-puppeteer-core
- 環境變量
- error-handling
- working-with-chrome-extensions
- class:puppeteer
- class:browserfetcher
- class:browser
- class:page
- class:worker
- class:accessibility
- class:keyboard
- class:mouse
- class:touchscreen
- class:tracing
- class:dialog
- class:consolemessage
- class:frame
- class:executioncontext
- class:jshandle
- class:elementhandle
- class:request
- class:response
- class:securitydetails
- class:target
- class:cdpsession
- class:coverage
- class:timeouterror