Skip to content
Back to archipelago.banuacoder.com

Debug Tools

How to inspect WebSocket frames in the Flutter debug panel ​

Enterprise Reference for app_debugger_websocket: every variable, option and package it generates. Command: archipelago generate app_debugger_websocket

Adds a WebSocket inspector to the debug panel. The tutorial sizes the ring buffer, adds the interceptor to your client and reads the frames grouped by endpoint, topic and event.

What you'll learn ​

  • Generating the WebSocket inspector sub-brick for app_debugger
  • Configuring the ring buffer
  • Adding the inspector interceptor to your WebSocket client
  • Reading the endpoint, topic and event tree in the panel

Prerequisites ​

Step 1: Generate the Brick ​

bash
archipelago generate app_debugger_websocket

The brick has no variables. It works with any WebSocket SDK you installed.

Step 2: Understand the Generated Packages ​

text
features/app_debugger_websocket/
├── app_debugger_websocket_api/     # WebSocketInspectorSDK, config and entry models
├── app_debugger_websocket/         # Debug implementation and WebSocket tab
│   └── lib/src/
│       ├── websocket_debugger_interceptor.dart
│       ├── websocket_inspector_page.dart
│       └── websocket_inspector_sdk_impl.dart
└── app_debugger_websocket_noop/    # Production-flavor stub

Step 3: Check build_prepare ​

The brick adds the swap entry to build_prepare.yaml for you:

yaml
build_prepare:
  mappings:
    - debug: app_debugger_websocket
      release: app_debugger_websocket_noop

The generated Fastfile runs dart run monorepo_toolkit build-prepare --flavor <flavor> before every build. Internal flavors keep the inspector, also in release mode. The production flavor gets the noop.

Step 4: Configure the Ring Buffer ​

The defaults suit most projects. Register your own WebSocketInspectorConfig to change them:

dart
getIt.registerSingleton<WebSocketInspectorConfig>(
  const WebSocketInspectorConfig(
    maxEntries: 500,
    capturePayloads: true,
    payloadTruncateLength: 2048,
  ),
);

A payload longer than payloadTruncateLength characters is truncated in the inspector. Your app still gets the full frame.

Step 5: Check the Wiring and Add the Interceptor ​

The hook adds GetIt.I<WebSocketInspectorSDK>(); at the archipelago:debug_panel_pages marker in app_debugger's lib/src/di/debug_tools.dart. This makes the WebSocket tab appear.

You add the interceptor yourself, after DI is ready:

dart
final wsInspector = getIt<WebSocketInspectorSDK>();
if (wsInspector.interceptor != null) {
  getIt<WebSocketClient>().addInterceptor(wsInspector.interceptor!);
}

The noop returns a null interceptor. The guard is safe to keep in shared code.

Step 6: Verify in an Internal Flavor ​

Open a WebSocket connection. Open the debug panel and tap WebSocket. The tab shows a tree:

text
wss://api.example.com/socket
└── chat
    ├── message.new     (12 frames)
    ├── message.read    (3 frames)
    └── presence.join   (1 frame)

Tap an event row to see its frames with timestamps and payloads.

Ring Buffer Reference ​

Config KeyDefaultNotes
maxEntries500The oldest frame goes first when full
capturePayloadstrueSet false to keep metadata only
payloadTruncateLength2048Characters kept per payload

Next Steps ​