WebSocket Inspector

AndroidiOSDesktop

The WebSocket Inspector captures WebSocket connections from your app. View connection URLs, sent and received frames, timestamps, payload contents, and close events -- all in real time.

Features

  • Capture WebSocket connections and frames
  • View sent and received messages with timestamps
  • Inspect frame payloads (text and binary)
  • Track connection open and close events
  • OkHttp integration and manual logging API

OkHttp Integration

If you use OkHttp for WebSocket connections, Snapbug provides extension methods that automatically capture all traffic.

Send Messages

Use sendWithSnapbug() instead of send() to log outgoing frames:

webSocket.sendWithSnapbug("Hello, server!")
webSocket.sendWithSnapbug(byteString)

Listen for Messages

Use listenWithSnapbug() to automatically log incoming frames:

val client = OkHttpClient()
val request = Request.Builder().url("wss://example.com/ws").build()
 
client.newWebSocket(request, object : WebSocketListener() {
    override fun onOpen(webSocket: WebSocket, response: Response) {
        webSocket.listenWithSnapbug(this)
    }
 
    override fun onMessage(webSocket: WebSocket, text: String) {
        // Your message handling logic
    }
 
    override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
        // Connection closed
    }
})

Manual Logging

For non-OkHttp WebSocket clients, use the manual logging API:

// Log a WebSocket event
snapbugLogWebSocketEvent(
    SnapbugWebSocketEvent(
        connectionId = "ws-1",
        url = "wss://example.com/ws",
        type = SnapbugWebSocketEvent.Type.MESSAGE_RECEIVED,
        payload = """{"action": "update", "data": {"id": 42}}""",
        timestamp = System.currentTimeMillis()
    )
)

Event Types

The SnapbugWebSocketEvent.Type enum includes:

TypeDescription
CONNECTION_OPENEDWebSocket connection established
MESSAGE_SENTFrame sent to the server
MESSAGE_RECEIVEDFrame received from the server
CONNECTION_CLOSEDWebSocket connection closed
CONNECTION_FAILEDConnection attempt failed
// Log connection opened
snapbugLogWebSocketEvent(
    SnapbugWebSocketEvent(
        connectionId = "ws-1",
        url = "wss://example.com/ws",
        type = SnapbugWebSocketEvent.Type.CONNECTION_OPENED,
        timestamp = System.currentTimeMillis()
    )
)
 
// Log connection closed
snapbugLogWebSocketEvent(
    SnapbugWebSocketEvent(
        connectionId = "ws-1",
        url = "wss://example.com/ws",
        type = SnapbugWebSocketEvent.Type.CONNECTION_CLOSED,
        payload = "1000: Normal closure",
        timestamp = System.currentTimeMillis()
    )
)
info

Use a consistent connectionId across all events for the same WebSocket connection. This allows the Desktop app to group events by connection.