List all targets (pages, workers, etc.).
(&mut self)
| 689 | |
| 690 | /// List all targets (pages, workers, etc.). |
| 691 | pub async fn get_all_targets(&mut self) -> Result<Vec<TargetInfo>> { |
| 692 | let result = self.send("Target.getTargets", json!({})).await?; |
| 693 | let targets = result["targetInfos"].as_array().ok_or_else(|| { |
| 694 | anyhow!("Malformed Target.getTargets response: missing 'targetInfos' array") |
| 695 | })?; |
| 696 | |
| 697 | let mut all = Vec::new(); |
| 698 | for t in targets { |
| 699 | all.push(TargetInfo { |
| 700 | target_id: t["targetId"] |
| 701 | .as_str() |
| 702 | .ok_or_else(|| anyhow!("Malformed TargetInfo: missing 'targetId'"))? |
| 703 | .to_string(), |
| 704 | title: t["title"].as_str().unwrap_or("").to_string(), |
| 705 | url: t["url"].as_str().unwrap_or("").to_string(), |
| 706 | target_type: t["type"].as_str().unwrap_or("").to_string(), |
| 707 | }); |
| 708 | } |
| 709 | Ok(all) |
| 710 | } |
| 711 | |
| 712 | /// Attach to a target and return the session ID for subsequent commands. |
| 713 | pub async fn attach_to_target(&mut self, target_id: &str) -> Result<String> { |