MCPcopy Create free account
hub / github.com/aeroxy/chrome-devtools-cli / collect_console

Function collect_console

src/commands/console.rs:9–43  ·  view source on GitHub ↗
(
    client: &mut CdpClient,
    session_id: &str,
    duration_ms: u64,
    type_filter: Vec<String>,
    format: OutputFormat,
)

Source from the content-addressed store, hash-verified

7use crate::result::CommandResult;
8
9pub 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
45fn process_console_events(
46 events: &[serde_json::Value],

Callers 2

run_directFunction · 0.85
inner_executeFunction · 0.85

Calls 5

process_console_eventsFunction · 0.85
format_console_outputFunction · 0.85
drain_console_eventsMethod · 0.80
read_events_forMethod · 0.80
send_to_targetMethod · 0.80

Tested by

no test coverage detected