ras_cdp/domain/
repository.rs1use async_trait::async_trait;
2use ras_errors::AppError;
3use ras_types::{BackendNodeId, TargetId};
4use serde::{Deserialize, Serialize};
5use url::Url;
6
7use crate::domain::viewport::Viewport;
8
9#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
10#[serde(rename_all = "lowercase")]
11pub enum ScreenshotFormat {
12 #[default]
13 Png,
14 Jpeg,
15}
16
17#[async_trait]
18pub trait BrowserPort: Send + Sync + 'static {
19 async fn cdp_url(&self) -> Result<Url, AppError>;
20 async fn list_targets(&self) -> Result<Vec<TargetId>, AppError>;
21 async fn focused_target(&self) -> Result<TargetId, AppError>;
22 async fn navigate(&self, target: &TargetId, url: &Url) -> Result<(), AppError>;
23 async fn evaluate(
24 &self,
25 target: &TargetId,
26 expression: &str,
27 ) -> Result<serde_json::Value, AppError>;
28 async fn click_at(&self, target: &TargetId, x: i32, y: i32) -> Result<(), AppError>;
29 async fn click_node(&self, target: &TargetId, node: BackendNodeId) -> Result<(), AppError>;
30 async fn type_text(&self, target: &TargetId, text: &str) -> Result<(), AppError>;
31 async fn screenshot(
32 &self,
33 target: &TargetId,
34 format: ScreenshotFormat,
35 ) -> Result<Vec<u8>, AppError>;
36 async fn set_viewport(&self, target: &TargetId, viewport: Viewport) -> Result<(), AppError>;
37 async fn close_target(&self, target: &TargetId) -> Result<(), AppError>;
38 async fn create_target(&self, url: &Url) -> Result<TargetId, AppError>;
39}