pub struct BrowserAgent { /* private fields */ }Expand description
Drives a single browser tab via BrowserActions. Wraps a CdpClient with
Page, Runtime, DOM, and Network already enabled.
Implementations§
Source§impl BrowserAgent
impl BrowserAgent
Sourcepub async fn connect(host: &str, port: u16) -> Result<Self>
pub async fn connect(host: &str, port: u16) -> Result<Self>
Connect to the first available page target and enable the domains actions depend on.
Sourcepub async fn connect_with_config(config: &Config) -> Result<Self>
pub async fn connect_with_config(config: &Config) -> Result<Self>
connect using config.host/config.port, then apply
config’s viewport size.
Sourcepub fn from_client(client: CdpClient) -> Self
pub fn from_client(client: CdpClient) -> Self
Wrap an already-connected client (domains are the caller’s responsibility).
Sourcepub fn capture_console(&self) -> Receiver<ConsoleMessage>
pub fn capture_console(&self) -> Receiver<ConsoleMessage>
Start capturing console.* calls from the page. Returns a receiver that
yields each call as a ConsoleMessage; capture continues until the agent
(and its underlying client) is dropped.
Sourcepub async fn execute(&self, action: BrowserAction) -> ActionResult
pub async fn execute(&self, action: BrowserAction) -> ActionResult
Run one action, capturing success/failure into an ActionResult instead of
returning Result.
Sourcepub async fn execute_many(
&self,
actions: Vec<BrowserAction>,
) -> Vec<ActionResult>
pub async fn execute_many( &self, actions: Vec<BrowserAction>, ) -> Vec<ActionResult>
Run each action in actions in order, continuing even if one fails.
Sourcepub async fn execute_json(&self, json_str: &str) -> ActionResult
pub async fn execute_json(&self, json_str: &str) -> ActionResult
Parse json_str as a BrowserAction (e.g. {"action": "navigate", "url": "..."}) and run it. Suited for dispatching LLM tool calls directly.