playwright/api/dialog.rs
1use crate::imp::{core::*, dialog::Dialog as Impl, prelude::*};
2
3/// `Dialog` objects are dispatched by page via the [page::Event::Dialog](crate::api::page::Event::Dialog) event.
4///
5/// An example of using `Dialog` class:
6///
7/// ```js
8/// const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
9///
10/// (async () => {
11/// const browser = await chromium.launch();
12/// const page = await browser.newPage();
13/// page.on('dialog', async dialog => {
14/// console.log(dialog.message());
15/// await dialog.dismiss();
16/// });
17/// await page.evaluate(() => alert('1'));
18/// await browser.close();
19/// })();
20/// ```
21///
22/// > NOTE: Dialogs are dismissed automatically, unless there is a [`event: Page.dialog`] listener. When listener is
23/// present, it **must** either [`method: Dialog.accept`] or [`method: Dialog.dismiss`] the dialog - otherwise the page will
24/// [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#never_blocking) waiting for the dialog, and
25/// actions like click will never finish.
26pub struct Dialog {
27 inner: Weak<Impl>
28}
29
30impl Dialog {
31 pub(crate) fn new(inner: Weak<Impl>) -> Self { Self { inner } }
32
33 ///// Returns when the dialog has been accepted.
34 ///// A text to enter in prompt. Does not cause any effects if the dialog's `type` is not prompt. Optional.
35 // fn accept(&self, prompt_text: Option<String>) -> Result<(), Arc<Error>> { todo!() }
36 ///// If dialog is prompt, returns default prompt value. Otherwise, returns empty string.
37 // fn default_value(&self) -> Result<String, Error> { todo!() }
38 ///// Returns when the dialog has been dismissed.
39 // fn dismiss(&self) -> Result<(), Arc<Error>> { todo!() }
40 ///// A message displayed in the dialog.
41 // fn message(&self) -> Result<String, Error> { todo!() }
42 ///// Returns dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`.
43 // fn r#type(&self) -> Result<String, Error> { todo!() }
44}