Skip to content

Add network request monitoring#16

Merged
Redth merged 9 commits into
mainfrom
feature/network-monitor
Mar 3, 2026
Merged

Add network request monitoring#16
Redth merged 9 commits into
mainfrom
feature/network-monitor

Conversation

@Redth
Copy link
Copy Markdown
Owner

@Redth Redth commented Feb 27, 2026

Network Request Monitoring

Adds comprehensive HTTP traffic interception and monitoring to MauiDevFlow, enabling developers to observe all HTTP requests their MAUI app makes in real-time.

Architecture

App code → HttpClient → DevFlowHttpHandler (DelegatingHandler)
                              │
                              ▼
                    NetworkRequestStore (ring buffer)
                         │              │
                    REST API        WebSocket
                  /api/network     /ws/network
                         │              │
                         ▼              ▼
              CLI: maui-devflow MAUI network

What's Included

Agent Core (in-app):

  • DevFlowHttpHandler — DelegatingHandler that wraps platform handlers (AndroidMessageHandler, NSUrlSessionHandler, etc.)
  • NetworkRequestStore — Thread-safe ring buffer (default 500 entries) with OnRequestCaptured event
  • Auto-injection via ConfigureHttpClientDefaults in AddMauiDevFlowAgent() — zero config for DI clients
  • DevFlowHttp.CreateClient() helper for non-DI HttpClients
  • Body capture: text up to 256KB, binary as base64, with truncation flags
  • REST endpoints: /api/network, /api/network/{id}, /api/network/clear
  • WebSocket endpoint: /ws/network with replay + live streaming

AgentHttpServer:

  • RFC 6455 WebSocket upgrade support (handshake, frame read/write, masking, ping/pong)
  • MapWebSocket() route registration alongside MapGet/MapPost
  • Header parsing in HTTP request reader

CLI Commands:

  • MAUI network — Live TUI monitor (streams requests in real-time)
  • MAUI network --json — JSONL streaming (one JSON object per line, AI-friendly)
  • MAUI network list [--host H] [--method M] [--json] — One-shot dump
  • MAUI network detail <id> — Full headers + body for a specific request
  • MAUI network clear — Clear captured buffer
  • Color-coded status output (2xx green, 4xx red, errors red)

Sample App:

  • New NetworkTestPage with buttons to make test HTTP requests (GET, POST, 404, error)

Testing

Tested on:

  • ✅ Mac Catalyst — requests captured, list/detail/clear/live monitor all working
  • ✅ Android — requests captured via emulator with adb forward
  • ✅ iOS Simulator — requests captured correctly

Key Design Decisions

  • DelegatingHandler (not platform swizzling) — cross-platform, safe, composable
  • WebSocket for live streaming (not HTTP polling) — real-time, efficient, bi-directional
  • Ring buffer (not unbounded) — memory-safe for mobile apps
  • Body capture limits (256KB default) — prevents memory issues with large uploads/downloads
  • JSONL mode — enables AI agents to parse network traffic programmatically

CI

  • Build: ✅ 0 errors
  • Tests: ✅ 94/94 pass

Redth and others added 7 commits February 27, 2026 09:49
- Add DevFlowHttpHandler (DelegatingHandler) for HTTP traffic interception
- Auto-inject via ConfigureHttpClientDefaults in AddMauiDevFlowAgent()
- Add NetworkRequestStore ring buffer (default 500 entries) with events
- Add DevFlowHttp static helper for non-DI HttpClient wrapping
- Add REST endpoints: /api/network, /api/network/{id}, /api/network/clear
- Add WebSocket endpoint /ws/network for real-time streaming with replay
- Add RFC 6455 WebSocket support to AgentHttpServer (upgrade, frames, ping/pong)
- Add CLI commands: MAUI network (live monitor), network list, network detail, network clear
- Add --json flag for JSONL streaming output (AI-friendly)
- Add --host and --method filter options
- Add Spectre.Console for rich terminal output
- Add NetworkTestPage to SampleMauiApp for testing
- Capture request/response headers, bodies (256KB limit), timing, status
- Tested on Mac Catalyst, Android, and iOS

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add TCP keepalive on WebSocket connections to prevent OS idle drops
- Add server-side WebSocket ping every 15 seconds
- Add auto-reconnect in CLI network monitor with '(reconnected)' indicator
- Improve error handling: don't crash on malformed JSON messages

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Upgrade CLI from net9.0 to net10.0 (C# 14) for XenoAtom.Terminal.UI
- Add XenoAtom.Terminal.UI v1.1.1 package
- Implement NetworkMonitorTui with DataGrid, detail view, keyboard nav
- DataGrid shows: Index, Method, URL, Status, Duration, Size, ContentType
- Enter key fetches full request/response details from agent API
- Color-coded status codes (green 2xx, yellow 3xx, red 4xx/5xx)
- WebSocket auto-reconnect with status indicator
- --json flag falls back to JSONL streaming mode

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace Terminal.Run with TerminalApp for proper dispatcher integration
- Use app.Post() for all UI state mutations from WebSocket background thread
- Remove State<bool> exit check from WS loop (was blocking on non-UI thread)
- Use CancellationToken exclusively for shutdown signaling

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…cking

- Replace single-pane Enter-to-detail view with HSplitter split-pane layout
- Remove ScrollViewer wrapper around DataGrid (was stealing keyboard events,
  causing CurrentCell.Row to always return -1)
- Replace computed bindings with explicit State<string> to fix
  ProcessBindingWrites crash (Collection was modified during enumeration)
- Wrap DataGrid document mutations in BeginUpdate() for batch safety
- Remove index re-numbering loop that triggered binding write storms
- Details pane auto-updates on arrow key navigation and mouse click

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Wire up ConfigureHttpClientDefaults with DevFlowHttpHandler in
GtkAgentServiceExtensions, matching the standard MAUI agent setup.
Add Microsoft.Extensions.Http package reference.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Link NetworkTestPage.xaml and code-behind from SampleMauiApp.
Register AddHttpClient() and AddTransient<NetworkTestPage>() in
Linux MauiProgram.cs to match the main app's DI configuration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Redth Redth force-pushed the feature/network-monitor branch from 1a15c61 to affd932 Compare March 3, 2026 15:15
Redth and others added 2 commits March 3, 2026 10:17
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…OS app

- Add early JS-side check for window.__chobitsuDebugEnabled in
  InjectDebugScriptCoreAsync to skip re-injection when Shell navigation
  recreates the native WebView but shares the JS process pool
- Add same-instance guard in mapper callbacks for iOS, macOS, and Android
  to prevent redundant OnWebViewCapturedAsync calls from property mapping
- Add missing NetworkTestPage linked files to SampleMauiApp.MacOS.csproj

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Redth Redth merged commit 232e76b into main Mar 3, 2026
2 checks passed
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