browser_use/tools/
go_back.rs

1use crate::error::{BrowserError, Result};
2use crate::tools::{Tool, ToolContext, ToolResult};
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6/// Parameters for the go_back tool (no parameters needed)
7#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
8pub struct GoBackParams {}
9
10/// Tool for navigating back in browser history
11#[derive(Default)]
12pub struct GoBackTool;
13
14impl Tool for GoBackTool {
15    type Params = GoBackParams;
16
17    fn name(&self) -> &str {
18        "go_back"
19    }
20
21    fn execute_typed(
22        &self,
23        _params: GoBackParams,
24        context: &mut ToolContext,
25    ) -> Result<ToolResult> {
26        context
27            .session
28            .go_back()
29            .map_err(|e| BrowserError::ToolExecutionFailed {
30                tool: "go_back".to_string(),
31                reason: e.to_string(),
32            })?;
33
34        // Get current URL after going back
35        let current_url = context.session.tab()?.get_url();
36
37        Ok(ToolResult::success_with(serde_json::json!({
38            "message": "Navigated back in history",
39            "url": current_url
40        })))
41    }
42}