(
client: &mut CdpClient,
session_id: &str,
output: Option<&str>,
)
| 69 | } |
| 70 | |
| 71 | async 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 | |
| 107 | async fn go_forward( |
| 108 | client: &mut CdpClient, |
no test coverage detected