From 313eeebd945163e83ad70db5f4b0e61cdcadca01 Mon Sep 17 00:00:00 2001 From: Moses Narrow <36607567+0pcom@users.noreply.github.com> Date: Thu, 5 Mar 2026 17:55:52 -0600 Subject: [PATCH] Fix WebSocket UTF-8 errors in dmsgpty-ui Use binary WebSocket mode instead of text mode for PTY data. PTY output contains bytes that aren't valid UTF-8 (raw terminal escape sequences, binary data). Text mode WebSocket frames require valid UTF-8, causing "Could not decode a text frame as UTF-8" errors and disconnects. Binary mode handles raw terminal data correctly while the frontend already supports ArrayBuffer messages. Changes: - ui.go: Change websocket.MessageText to websocket.MessageBinary --- pkg/dmsgpty/ui.go | 3 ++- pkg/dmsgpty/ui_html.go | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/dmsgpty/ui.go b/pkg/dmsgpty/ui.go index 8315f507..bcdc1ae8 100644 --- a/pkg/dmsgpty/ui.go +++ b/pkg/dmsgpty/ui.go @@ -136,7 +136,8 @@ func (ui *UI) Handler(customCommands map[string][]string) http.HandlerFunc { } defer func() { log.WithError(ws.Close(websocket.StatusNormalClosure, "closed")).Debug("Closed ws.") }() - wsConn := websocket.NetConn(r.Context(), ws, websocket.MessageText) + // Use binary mode for PTY data - text mode fails on non-UTF-8 bytes + wsConn := websocket.NetConn(r.Context(), ws, websocket.MessageBinary) // open pty logWS(wsConn, "Dialing...") diff --git a/pkg/dmsgpty/ui_html.go b/pkg/dmsgpty/ui_html.go index 841ca793..084efa10 100644 --- a/pkg/dmsgpty/ui_html.go +++ b/pkg/dmsgpty/ui_html.go @@ -4318,7 +4318,6 @@ func writeTermHTML(w io.Writer) (int64, error) { if err != nil { return 0, err } - defer gz.Close() //nolint - return io.Copy(w, gz) //nolint:gosec // HTML is trusted content + return io.Copy(w, gz) //nolint:gosec // G110: embedded content is trusted }