chromewright 0.2.3

Browser automation MCP server and Rust library via Chrome DevTools Protocol (CDP)
Documentation
use crate::error::{BrowserError, Result};
use crate::tools::{
    DocumentEnvelopeOptions, Tool, ToolContext, ToolResult, build_document_envelope,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

/// Parameters for the go_forward tool (no parameters needed)
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct GoForwardParams {}

/// Tool for navigating forward in browser history
#[derive(Default)]
pub struct GoForwardTool;

#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct GoForwardOutput {
    #[serde(flatten)]
    pub envelope: crate::tools::DocumentEnvelope,
    pub action: String,
}

impl Tool for GoForwardTool {
    type Params = GoForwardParams;
    type Output = GoForwardOutput;

    fn name(&self) -> &str {
        "go_forward"
    }

    fn execute_typed(
        &self,
        _params: GoForwardParams,
        context: &mut ToolContext,
    ) -> Result<ToolResult> {
        context
            .session
            .go_forward()
            .map_err(|e| BrowserError::ToolExecutionFailed {
                tool: "go_forward".to_string(),
                reason: e.to_string(),
            })?;

        context.invalidate_dom();
        Ok(ToolResult::success_with(GoForwardOutput {
            envelope: build_document_envelope(context, None, DocumentEnvelopeOptions::minimal())?,
            action: "go_forward".to_string(),
        }))
    }
}