(
inspector_reader: &mut R,
inspector_writer: &mut W,
connection_id: &str,
app_id: &str,
page_id: u64,
)
| 576 | } |
| 577 | |
| 578 | async fn prepare_webkit_target_for_attach<R, W>( |
| 579 | inspector_reader: &mut R, |
| 580 | inspector_writer: &mut W, |
| 581 | connection_id: &str, |
| 582 | app_id: &str, |
| 583 | page_id: u64, |
| 584 | ) -> Result<(), AppError> |
| 585 | where |
| 586 | R: AsyncRead + Unpin, |
| 587 | W: AsyncWrite + Unpin, |
| 588 | { |
| 589 | send_forward_get_listing(inspector_writer, connection_id, app_id).await?; |
| 590 | let deadline = Instant::now() + WEBKIT_TARGET_ATTACH_TIMEOUT; |
| 591 | let mut released_connections = HashSet::new(); |
| 592 | |
| 593 | loop { |
| 594 | let Some(remaining) = deadline.checked_duration_since(Instant::now()) else { |
| 595 | return Err(AppError::native(format!( |
| 596 | "Timed out preparing WebKit target {app_id}/{page_id} for inspection." |
| 597 | ))); |
| 598 | }; |
| 599 | let packet = timeout( |
| 600 | remaining.min(Duration::from_millis(500)), |
| 601 | read_packet(inspector_reader), |
| 602 | ) |
| 603 | .await; |
| 604 | let packet = match packet { |
| 605 | Ok(Ok(packet)) => packet, |
| 606 | Ok(Err(error)) => return Err(error), |
| 607 | Err(_) => continue, |
| 608 | }; |
| 609 | |
| 610 | let message = parse_rpc_message(&packet)?; |
| 611 | match message.selector.as_str() { |
| 612 | "_rpc_applicationSentListing:" => { |
| 613 | if string_value(&message.args, "WIRApplicationIdentifierKey").as_deref() |
| 614 | != Some(app_id) |
| 615 | { |
| 616 | continue; |
| 617 | } |
| 618 | |
| 619 | let Some(page) = parse_page_listing(&message.args) |
| 620 | .into_iter() |
| 621 | .find(|page| page.page_id == page_id) |
| 622 | else { |
| 623 | return Err(AppError::not_found(format!( |
| 624 | "WebKit target {app_id}/{page_id} is no longer available." |
| 625 | ))); |
| 626 | }; |
| 627 | |
| 628 | let Some(existing_connection_id) = page.connection_id else { |
| 629 | return Ok(()); |
| 630 | }; |
| 631 | if existing_connection_id == connection_id { |
| 632 | return Ok(()); |
| 633 | } |
| 634 | if !released_connections.insert(existing_connection_id.clone()) { |
| 635 | send_forward_get_listing(inspector_writer, connection_id, app_id).await?; |
no test coverage detected