pub struct DialogManager { /* private fields */ }Expand description
Manages dialog event handlers for browser automation.
The DialogManager allows registering callbacks that are invoked
whenever a browser dialog (alert, confirm, prompt) is triggered.
It is engine-agnostic: the engine-specific dialog interception
logic calls DialogManager::dispatch when a dialog event occurs.
§Thread Safety
DialogManager is thread-safe and can be shared across async tasks.
§Example
use browser_commander::core::dialog::{DialogEvent, DialogManager};
let mut manager = DialogManager::new();
manager.on_dialog(|event| {
println!("Got dialog: {:?} - {}", event.dialog_type, event.message);
});
// Simulate dispatching a dialog (engine would call this internally)
let event = DialogEvent::from_str_type("alert", "Hello!", None);
manager.dispatch(&event);Implementations§
Source§impl DialogManager
impl DialogManager
Sourcepub fn new_with_engine(engine: EngineType) -> Self
pub fn new_with_engine(engine: EngineType) -> Self
Create a new DialogManager for the given engine.
Sourcepub fn on_dialog<F>(&mut self, handler: F)
pub fn on_dialog<F>(&mut self, handler: F)
Register a dialog handler.
The handler is called synchronously whenever a dialog event is dispatched.
For async handling, dispatch a channel message or use tokio::spawn inside
the handler.
§Arguments
handler- A function that receives aDialogEventreference.
Sourcepub fn clear_dialog_handlers(&mut self)
pub fn clear_dialog_handlers(&mut self)
Remove all registered dialog handlers.
Sourcepub fn handler_count(&self) -> usize
pub fn handler_count(&self) -> usize
Get the number of registered handlers.
Sourcepub fn dispatch(&self, event: &DialogEvent)
pub fn dispatch(&self, event: &DialogEvent)
Dispatch a dialog event to all registered handlers.
This is called by the engine-specific integration when a dialog appears. If no handlers are registered, this is a no-op (the engine integration should auto-dismiss the dialog in that case).
§Arguments
event- The dialog event to dispatch.
Sourcepub fn engine(&self) -> EngineType
pub fn engine(&self) -> EngineType
Get the engine type this manager is associated with.
Trait Implementations§
Source§impl Clone for DialogManager
impl Clone for DialogManager
Source§fn clone(&self) -> DialogManager
fn clone(&self) -> DialogManager
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more