use std::future::Future;
use super::BrowserContext;
use super::events::{HandlerId, WaitForPageBuilder};
use crate::error::ContextError;
use crate::page::Page;
impl BrowserContext {
pub async fn on_page<F, Fut>(&self, handler: F) -> HandlerId
where
F: Fn(Page) -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
{
self.event_manager.on_page(handler).await
}
pub async fn off_page(&self, handler_id: HandlerId) -> bool {
self.event_manager.off_page(handler_id).await
}
pub async fn on_close<F, Fut>(&self, handler: F) -> HandlerId
where
F: Fn() -> Fut + Send + Sync + 'static,
Fut: Future<Output = ()> + Send + 'static,
{
self.event_manager.on_close(handler).await
}
pub async fn off_close(&self, handler_id: HandlerId) -> bool {
self.event_manager.off_close(handler_id).await
}
pub fn wait_for_page<F, Fut>(&self, action: F) -> WaitForPageBuilder<'_, F, Fut>
where
F: FnOnce() -> Fut,
Fut: Future<Output = Result<(), ContextError>>,
{
WaitForPageBuilder::new(&self.event_manager, action)
}
}