#[derive(Debug, Clone)]
pub struct BrowserBackendError {
message: String,
}
impl BrowserBackendError {
#[must_use]
pub fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
}
impl std::fmt::Display for BrowserBackendError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "browser backend error: {}", self.message)
}
}
impl std::error::Error for BrowserBackendError {}
pub trait BrowserBackend: Send + Sync {
fn cdp_endpoint(&self) -> impl Future<Output = Result<String, BrowserBackendError>> + Send;
}
#[derive(Debug, Clone)]
pub struct StaticCdpBrowser {
endpoint: String,
}
impl StaticCdpBrowser {
#[must_use]
pub fn new(endpoint: impl Into<String>) -> Self {
Self {
endpoint: endpoint.into(),
}
}
}
impl BrowserBackend for StaticCdpBrowser {
fn cdp_endpoint(&self) -> impl Future<Output = Result<String, BrowserBackendError>> {
std::future::ready(Ok(self.endpoint.clone()))
}
}