Skip to content

[kernel-1116] browser debug: add cdp monitor#202

Open
archandatta wants to merge 13 commits intoarchand/kernel-1116/cdp-pipelinefrom
archand/kernel-1116/cdp-monitor
Open

[kernel-1116] browser debug: add cdp monitor#202
archandatta wants to merge 13 commits intoarchand/kernel-1116/cdp-pipelinefrom
archand/kernel-1116/cdp-monitor

Conversation

@archandatta
Copy link
Copy Markdown
Contributor

@archandatta archandatta commented Apr 6, 2026

Tests

  • run the chromium-headful image
  • run curl -v -X POST http://localhost:444/events/start to start the event capture stream
  • look through the docker container logs for /var/logs/ and there should files created for console.log, network.log etc.

I did some browsing and started a yt video and got these logs from it:

  • network.log was the largest - open to thoughts on filtering some of it to reduce the size

    • Static assets (by MIME type):
    • Images: image/svg+xml (111), image/gif (45), image/jpeg (17), image/png
      (14), image/avif (14), image/x-icon (12), image/webp (1)
    • JavaScript: text/javascript (69), application/x-javascript (25),
      application/javascript (4)
    • CSS: text/css (34)
    • Fonts: font/woff2 (15)
    • Media: audio/mpeg (4), application/vnd.yt-ump (7)

    Other skipped:

    • text/html (23) — these are likely iframe/subframe HTML documents where
      the body fetch returned empty or the resource type was filtered

    What we ARE capturing bodies for (30 responses):

    • application/json (21) — API responses, the most useful data
    • text/plain (3)
    • text/html (2) — top-level page HTML
    • application/json+protobuf (2)
    • application/manifest+json (1)
  ┌─────────────────┬───────┬─────────────────────────────────────────────┐
  │    Log File     │ Lines │                 Event Types                 │
  ├─────────────────┼───────┼─────────────────────────────────────────────┤
  │ console.log     │ 2     │ console_log (2)                             │
  ├─────────────────┼───────┼─────────────────────────────────────────────┤
  │                 │       │ network_request (483), network_response     │
  │ network.log     │ 921   │ (417), network_loading_failed (18),         │
  │                 │       │ network_idle (3)                            │
  ├─────────────────┼───────┼─────────────────────────────────────────────┤
  │                 │       │ layout_shift (28), navigation (13),         │
  │ page.log        │ 55    │ dom_content_loaded (5), page_load (5),      │
  │                 │       │ layout_settled (3), navigation_settled (1)  │
  ├─────────────────┼───────┼─────────────────────────────────────────────┤
  │ interaction.log │ 9     │ interaction_click (7), interaction_key (1), │
  │                 │       │  scroll_settled (1)                         │
  ├─────────────────┼───────┼─────────────────────────────────────────────┤
  │ system.log      │ 4     │ screenshot (4)                              │
  └─────────────────┴───────┴─────────────────────────────────────────────┘
  ┌─────────────────┬──────┐
  │      File       │ Size │
  ├─────────────────┼──────┤
  │ console.log     │ 19K  │
  ├─────────────────┼──────┤
  │ interaction.log │ 4.5K │
  ├─────────────────┼──────┤
  │ network.log     │ 2.3M │
  ├─────────────────┼──────┤
  │ page.log        │ 40K  │
  ├─────────────────┼──────┤
  │ system.log      │ 658K │
  └─────────────────┴──────┘

Note

Medium Risk
Adds a substantial new CDP WebSocket monitor (network/body capture, injected JS, timers, reconnect/backoff) and adjusts global events.CategoryFor parsing, which could affect event categorization across the pipeline.

Overview
Introduces a full cdpmonitor implementation that connects to Chrome DevTools via WebSocket, auto-attaches to page targets (including pre-existing ones), enables key CDP domains, and injects interaction.js to emit click/key/scroll events via a runtime binding.

Adds event handlers that publish normalized events for console output/exceptions, navigation/DOM/page load, network requests/responses (optionally fetching and truncating textual bodies while skipping binary types), and layout shifts; plus computed meta-events (network_idle, layout_settled, navigation_settled) driven by debounced timers.

Implements lifecycle management with safe Start/Stop, in-flight command unblocking, and upstream-restart reconnection with backoff and monitor_disconnected/monitor_reconnected events, and adds rate-limited screenshot capture via ffmpeg with downscaling to stay under size thresholds. Updates events.CategoryFor to derive categories from underscore-delimited event types (and treats layout_* as page events).

Reviewed by Cursor Bugbot for commit 0e65e19. Bugbot is set up for automated code reviews on this repo. Configure here.

@archandatta archandatta marked this pull request as ready for review April 6, 2026 13:41
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0e65e19. Configure here.

}
data, _ := json.Marshal(ev)
m.publishEvent(EventNetworkRequest, events.DetailStandard, events.Source{Kind: events.KindCDP}, "Network.requestWillBeSent", data, sessionID)
m.computed.onRequest()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redirect requests double-increment netPending, blocking network_idle

High Severity

handleNetworkRequest unconditionally calls m.computed.onRequest() (incrementing netPending) for every Network.requestWillBeSent event. In CDP, HTTP redirects reuse the same requestId and fire additional requestWillBeSent events (with a redirectResponse field), but only a single loadingFinished fires per chain. The pendingRequests map correctly overwrites the entry, but netPending gets incremented again without a corresponding decrement. This permanently inflates netPending, preventing network_idle and navigation_settled from ever firing on pages with any HTTP redirects.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0e65e19. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant