pub struct Dialog { /* private fields */ }Expand description
A browser dialog (alert, confirm, prompt, or beforeunload).
Dialogs are emitted via the page.on_dialog() callback. You must either
accept() or dismiss() the dialog - otherwise the page will freeze
waiting for user input.
§Example
page.on_dialog(|dialog| async move {
println!("Dialog message: {}", dialog.message());
dialog.accept().await
});Implementations§
Source§impl Dialog
impl Dialog
Sourcepub fn type_(&self) -> DialogType
pub fn type_(&self) -> DialogType
Get the dialog type.
Returns one of: alert, confirm, prompt, or beforeunload.
Sourcepub fn default_value(&self) -> &str
pub fn default_value(&self) -> &str
Get the default prompt value.
Only applicable for prompt dialogs.
Sourcepub async fn accept(self) -> Result<(), PageError>
pub async fn accept(self) -> Result<(), PageError>
Accept the dialog.
For alert dialogs, this closes the dialog.
For confirm dialogs, this returns true to the JavaScript.
For prompt dialogs, this returns the default value to the JavaScript.
For beforeunload dialogs, this allows navigation to proceed.
§Errors
Returns an error if the dialog has already been handled or CDP fails.
Sourcepub async fn accept_with_text(
self,
text: impl Into<String>,
) -> Result<(), PageError>
pub async fn accept_with_text( self, text: impl Into<String>, ) -> Result<(), PageError>
Accept the dialog with the specified text.
This is primarily useful for prompt dialogs where you want to
provide a custom response.
§Errors
Returns an error if the dialog has already been handled or CDP fails.
Sourcepub async fn dismiss(self) -> Result<(), PageError>
pub async fn dismiss(self) -> Result<(), PageError>
Dismiss the dialog.
For alert dialogs, this closes the dialog.
For confirm dialogs, this returns false to the JavaScript.
For prompt dialogs, this returns null to the JavaScript.
For beforeunload dialogs, this cancels navigation.
§Errors
Returns an error if the dialog has already been handled or CDP fails.