MCPcopy Create free account
hub / github.com/aeroxy/chrome-devtools-cli / go_back

Function go_back

src/commands/navigate.rs:71–105  ·  view source on GitHub ↗
(
    client: &mut CdpClient,
    session_id: &str,
    output: Option<&str>,
)

Source from the content-addressed store, hash-verified

69}
70
71async fn go_back(
72 client: &mut CdpClient,
73 session_id: &str,
74 output: Option<&str>,
75) -> Result<CommandResult> {
76 let history = client
77 .send_to_target(session_id, "Page.getNavigationHistory", json!({}))
78 .await?;
79
80 let current_index = history["currentIndex"].as_i64().unwrap_or(0);
81 let entries = history["entries"]
82 .as_array()
83 .ok_or_else(|| anyhow::anyhow!("No navigation history entries"))?;
84
85 if current_index <= 0 {
86 bail!("Already at the beginning of history");
87 }
88
89 let prev_entry = &entries[(current_index - 1) as usize];
90 let entry_id = prev_entry["id"].as_i64().unwrap_or(0);
91
92 client
93 .send_to_target(
94 session_id,
95 "Page.navigateToHistoryEntry",
96 json!({"entryId": entry_id}),
97 )
98 .await?;
99
100 wait_for_load(client, session_id, NAVIGATION_TIMEOUT_MS).await?;
101 let url = prev_entry["url"].as_str().unwrap_or("unknown");
102 let result = CommandResult::output(format!("Navigated back to {url}"))
103 .with_navigated_to(url.to_string());
104 Ok(result.save_output(output).await?)
105}
106
107async fn go_forward(
108 client: &mut CdpClient,

Callers 1

navigateFunction · 0.85

Calls 4

wait_for_loadFunction · 0.85
send_to_targetMethod · 0.80
with_navigated_toMethod · 0.80
save_outputMethod · 0.80

Tested by

no test coverage detected