browser_use/tools/
navigate.rs1use crate::error::Result;
2use crate::tools::snapshot::{RenderMode, render_aria_tree};
3use crate::tools::utils::normalize_url;
4use crate::tools::{Tool, ToolContext, ToolResult};
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
10pub struct NavigateParams {
11 pub url: String,
13
14 #[serde(default = "default_wait")]
16 pub wait_for_load: bool,
17}
18
19fn default_wait() -> bool {
20 true
21}
22
23#[derive(Default)]
25pub struct NavigateTool;
26
27impl Tool for NavigateTool {
28 type Params = NavigateParams;
29
30 fn name(&self) -> &str {
31 "navigate"
32 }
33
34 fn execute_typed(
35 &self,
36 params: NavigateParams,
37 context: &mut ToolContext,
38 ) -> Result<ToolResult> {
39 let normalized_url = normalize_url(¶ms.url);
41
42 context.session.navigate(&normalized_url)?;
44
45 if params.wait_for_load {
47 context.session.wait_for_navigation()?;
48 }
49
50 let snapshot = {
51 let dom = context.get_dom()?;
52 render_aria_tree(&dom.root, RenderMode::Ai, None)
53 };
54
55 Ok(ToolResult::success_with(serde_json::json!({
56 "snapshot": snapshot
57 })))
58 }
59}