(
client: &mut CdpClient,
session_id: &str,
duration_ms: u64,
type_filter: Vec<String>,
format: OutputFormat,
)
| 7 | use crate::result::CommandResult; |
| 8 | |
| 9 | pub async fn collect_console( |
| 10 | client: &mut CdpClient, |
| 11 | session_id: &str, |
| 12 | duration_ms: u64, |
| 13 | type_filter: Vec<String>, |
| 14 | format: OutputFormat, |
| 15 | ) -> Result<CommandResult> { |
| 16 | let events = if duration_ms == 0 { |
| 17 | // Drain mode: return accumulated events from the persistent session. |
| 18 | client.drain_console_events() |
| 19 | } else if client.persistent_session.is_some() { |
| 20 | // Live mode, daemon: the persistent session already has Runtime enabled |
| 21 | // and push_event accumulates its events into console_events. Read for the |
| 22 | // window so they land in the buffer, then drain the buffer as the single |
| 23 | // source of truth. Draining also consumes them, so a later drain can't |
| 24 | // repeat them (read_events_for's own return value would double-count). |
| 25 | client.read_events_for(duration_ms).await?; |
| 26 | client.drain_console_events() |
| 27 | } else { |
| 28 | // Live mode, direct/fallback: no persistent buffer. Enable Runtime on our |
| 29 | // own session, collect for the window, disable, and return what we read. |
| 30 | client |
| 31 | .send_to_target(session_id, "Runtime.enable", json!({})) |
| 32 | .await?; |
| 33 | let events_result = client.read_events_for(duration_ms).await; |
| 34 | let _ = client |
| 35 | .send_to_target(session_id, "Runtime.disable", json!({})) |
| 36 | .await; |
| 37 | events_result? |
| 38 | }; |
| 39 | |
| 40 | let messages = process_console_events(&events, &type_filter); |
| 41 | |
| 42 | format_console_output(&messages, format) |
| 43 | } |
| 44 | |
| 45 | fn process_console_events( |
| 46 | events: &[serde_json::Value], |
no test coverage detected