List all open page targets.
(&mut self)
| 660 | |
| 661 | /// List all open page targets. |
| 662 | pub async fn get_page_targets(&mut self) -> Result<Vec<TargetInfo>> { |
| 663 | let result = self.send("Target.getTargets", json!({})).await?; |
| 664 | let targets = result["targetInfos"].as_array().ok_or_else(|| { |
| 665 | anyhow!("Malformed Target.getTargets response: missing 'targetInfos' array") |
| 666 | })?; |
| 667 | |
| 668 | let mut pages = Vec::new(); |
| 669 | for t in targets { |
| 670 | let target_type = t["type"].as_str().unwrap_or(""); |
| 671 | if target_type == "page" { |
| 672 | let target_id = t["targetId"] |
| 673 | .as_str() |
| 674 | .ok_or_else(|| anyhow!("Malformed TargetInfo: missing 'targetId'"))? |
| 675 | .to_string(); |
| 676 | let title = t["title"].as_str().unwrap_or("").to_string(); |
| 677 | let url = t["url"].as_str().unwrap_or("").to_string(); |
| 678 | |
| 679 | pages.push(TargetInfo { |
| 680 | target_id, |
| 681 | title, |
| 682 | url, |
| 683 | target_type: target_type.to_string(), |
| 684 | }); |
| 685 | } |
| 686 | } |
| 687 | Ok(pages) |
| 688 | } |
| 689 | |
| 690 | /// List all targets (pages, workers, etc.). |
| 691 | pub async fn get_all_targets(&mut self) -> Result<Vec<TargetInfo>> { |
no test coverage detected