Skip to main content

limit_cli/tools/browser/client_ext/
navigation.rs

1//! Navigation operations
2
3use crate::tools::browser::executor::BrowserError;
4
5/// Navigation operations for browser client
6pub trait NavigationExt {
7    /// Navigate back in browser history
8    fn back(&self) -> impl std::future::Future<Output = Result<(), BrowserError>> + Send;
9    /// Navigate forward in browser history
10    fn forward(&self) -> impl std::future::Future<Output = Result<(), BrowserError>> + Send;
11    /// Reload the current page
12    fn reload(&self) -> impl std::future::Future<Output = Result<(), BrowserError>> + Send;
13}
14
15impl NavigationExt for super::super::BrowserClient {
16    async fn back(&self) -> Result<(), BrowserError> {
17        let output = self.executor().execute(&["back"]).await?;
18
19        if output.success {
20            Ok(())
21        } else {
22            Err(BrowserError::Other(format!(
23                "Failed to navigate back: {}",
24                output.stderr
25            )))
26        }
27    }
28
29    async fn forward(&self) -> Result<(), BrowserError> {
30        let output = self.executor().execute(&["forward"]).await?;
31
32        if output.success {
33            Ok(())
34        } else {
35            Err(BrowserError::Other(format!(
36                "Failed to navigate forward: {}",
37                output.stderr
38            )))
39        }
40    }
41
42    async fn reload(&self) -> Result<(), BrowserError> {
43        let output = self.executor().execute(&["reload"]).await?;
44
45        if output.success {
46            Ok(())
47        } else {
48            Err(BrowserError::Other(format!(
49                "Failed to reload page: {}",
50                output.stderr
51            )))
52        }
53    }
54}