Get the current page URL via JavaScript evaluation.
(&mut self, session_id: &str)
| 812 | |
| 813 | /// Get the current page URL via JavaScript evaluation. |
| 814 | pub async fn current_url(&mut self, session_id: &str) -> Result<String> { |
| 815 | let result = self |
| 816 | .send_to_target( |
| 817 | session_id, |
| 818 | "Runtime.evaluate", |
| 819 | json!({"expression": "window.location.href", "returnByValue": true}), |
| 820 | ) |
| 821 | .await?; |
| 822 | result["result"]["value"] |
| 823 | .as_str() |
| 824 | .map(|s| s.to_string()) |
| 825 | .ok_or_else(|| { |
| 826 | anyhow!( |
| 827 | "Failed to get current URL: evaluation did not return a string. Result: {}", |
| 828 | result |
| 829 | ) |
| 830 | }) |
| 831 | } |
| 832 | |
| 833 | /// Resolve which page to operate on. |
| 834 | /// Priority: --target (by ID or friendly name) > --page (by index) > first page. |
no test coverage detected