aither_agent/
browser_backend.rs1use std::future::Future;
4use std::pin::Pin;
5
6#[derive(Debug, Clone)]
8pub struct BrowserBackendError {
9 message: String,
10}
11
12impl BrowserBackendError {
13 #[must_use]
15 pub fn new(message: impl Into<String>) -> Self {
16 Self {
17 message: message.into(),
18 }
19 }
20}
21
22impl std::fmt::Display for BrowserBackendError {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 write!(f, "browser backend error: {}", self.message)
25 }
26}
27
28impl std::error::Error for BrowserBackendError {}
29
30pub trait BrowserBackend: Send + Sync {
35 fn cdp_endpoint(
37 &self,
38 ) -> Pin<Box<dyn Future<Output = Result<String, BrowserBackendError>> + Send + '_>>;
39}
40
41#[derive(Debug, Clone)]
43pub struct StaticCdpBrowser {
44 endpoint: String,
45}
46
47impl StaticCdpBrowser {
48 #[must_use]
50 pub fn new(endpoint: impl Into<String>) -> Self {
51 Self {
52 endpoint: endpoint.into(),
53 }
54 }
55}
56
57impl BrowserBackend for StaticCdpBrowser {
58 fn cdp_endpoint(
59 &self,
60 ) -> Pin<Box<dyn Future<Output = Result<String, BrowserBackendError>> + Send + '_>> {
61 Box::pin(async move { Ok(self.endpoint.clone()) })
62 }
63}