diff --git a/src/cdp.rs b/src/cdp.rs index 5415a55..f360d86 100644 --- a/src/cdp.rs +++ b/src/cdp.rs @@ -1422,7 +1422,7 @@ impl Executor for CdpExecutor { } } -fn discover_websocket_url(config: &CdpConfig) -> Result { +fn fetch_json_targets(config: &CdpConfig) -> Result { let mut stream = TcpStream::connect_timeout(&config.endpoint(), MAX_IO_TIMEOUT) .map_err(|_| CdpError::Protocol)?; stream @@ -1486,7 +1486,11 @@ fn discover_websocket_url(config: &CdpConfig) -> Result { if body.len() != content_length { return Err(CdpError::Protocol); } - let targets: Value = serde_json::from_slice(&body).map_err(|_| CdpError::Protocol)?; + serde_json::from_slice(&body).map_err(|_| CdpError::Protocol) +} + +fn discover_websocket_url(config: &CdpConfig) -> Result { + let targets = fetch_json_targets(config)?; let mut matches = targets .as_array() .ok_or(CdpError::Protocol)?