(
inspector_reader: &mut R,
app_id: &str,
page_id: u64,
sender_id: &str,
)
| 675 | } |
| 676 | |
| 677 | async fn wait_for_webkit_socket_setup<R>( |
| 678 | inspector_reader: &mut R, |
| 679 | app_id: &str, |
| 680 | page_id: u64, |
| 681 | sender_id: &str, |
| 682 | ) -> Result<Vec<String>, AppError> |
| 683 | where |
| 684 | R: AsyncRead + Unpin, |
| 685 | { |
| 686 | let deadline = Instant::now() + WEBKIT_TARGET_ATTACH_TIMEOUT; |
| 687 | loop { |
| 688 | let Some(remaining) = deadline.checked_duration_since(Instant::now()) else { |
| 689 | return Err(AppError::native(format!( |
| 690 | "WebKit target {app_id}/{page_id} did not acknowledge inspector socket setup." |
| 691 | ))); |
| 692 | }; |
| 693 | let packet = timeout( |
| 694 | remaining.min(Duration::from_millis(500)), |
| 695 | read_packet(inspector_reader), |
| 696 | ) |
| 697 | .await; |
| 698 | let packet = match packet { |
| 699 | Ok(Ok(packet)) => packet, |
| 700 | Ok(Err(error)) => return Err(error), |
| 701 | Err(_) => continue, |
| 702 | }; |
| 703 | |
| 704 | let message = parse_rpc_message(&packet)?; |
| 705 | match message.selector.as_str() { |
| 706 | "_rpc_applicationSentData:" => { |
| 707 | if string_value(&message.args, "WIRDestinationKey").as_deref() == Some(sender_id) { |
| 708 | if let Some(data) = data_value(&message.args, "WIRMessageDataKey") { |
| 709 | return Ok(vec![String::from_utf8(data).unwrap_or_default()]); |
| 710 | } |
| 711 | } |
| 712 | } |
| 713 | "_rpc_applicationDisconnected:" => { |
| 714 | if string_value(&message.args, "WIRApplicationIdentifierKey").as_deref() |
| 715 | == Some(app_id) |
| 716 | { |
| 717 | return Err(AppError::not_found(format!( |
| 718 | "WebKit application {app_id} disconnected before inspection could start." |
| 719 | ))); |
| 720 | } |
| 721 | } |
| 722 | "_rpc_applicationSentListing:" |
| 723 | | "_rpc_applicationUpdated:" |
| 724 | | "_rpc_reportSetup:" |
| 725 | | "_rpc_reportCurrentState:" |
| 726 | | "_rpc_reportConnectedApplicationList:" |
| 727 | | "_rpc_reportConnectedDriverList:" => {} |
| 728 | selector => debug!("Ignoring WebKit inspector setup selector {selector}."), |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | async fn discover_webinspector_socket(udid: &str) -> Result<Option<WebKitSocket>, AppError> { |
| 734 | let output = timeout( |
no test coverage detected