From fd8cc978d4cc439973a94d352369abca7ae183cb Mon Sep 17 00:00:00 2001 From: Olivier Chafik Date: Thu, 12 Feb 2026 15:28:32 +0000 Subject: [PATCH] fix(message-transport): only ignore messages that lack jsonrpc: "2.0" (#448) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tighten the parse-failure handler: silently ignore postMessage frames where event.data?.jsonrpc !== "2.0" (i.e. not JSON-RPC at all — null, undefined, a primitive, or an object from the host environment that doesn't carry the jsonrpc field). Messages that do carry jsonrpc: "2.0" but are otherwise malformed still surface via onerror so genuine protocol errors aren't swallowed. https://claude.ai/code/session_01DaJpUtSJf4hA7tnu3nJz8s Co-authored-by: Claude --- src/message-transport.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/message-transport.ts b/src/message-transport.ts index c49aa77..dded704 100644 --- a/src/message-transport.ts +++ b/src/message-transport.ts @@ -82,7 +82,17 @@ export class PostMessageTransport implements Transport { if (parsed.success) { console.debug("Parsed message", parsed.data); this.onmessage?.(parsed.data); + } else if (event.data?.jsonrpc !== "2.0") { + // Not a JSON-RPC message at all (e.g. internal frames injected by + // the host environment). Ignore silently so the transport stays alive. + console.debug( + "Ignoring non-JSON-RPC message", + parsed.error.message, + event, + ); } else { + // Has jsonrpc: "2.0" but is otherwise malformed — surface as a real + // protocol error. console.error("Failed to parse message", parsed.error.message, event); this.onerror?.( new Error(