Skip to content

Commit fd8cc97

Browse files
ochafikclaude
andauthored
fix(message-transport): only ignore messages that lack jsonrpc: "2.0" (#448)
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 <noreply@anthropic.com>
1 parent a815f31 commit fd8cc97

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/message-transport.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,17 @@ export class PostMessageTransport implements Transport {
8282
if (parsed.success) {
8383
console.debug("Parsed message", parsed.data);
8484
this.onmessage?.(parsed.data);
85+
} else if (event.data?.jsonrpc !== "2.0") {
86+
// Not a JSON-RPC message at all (e.g. internal frames injected by
87+
// the host environment). Ignore silently so the transport stays alive.
88+
console.debug(
89+
"Ignoring non-JSON-RPC message",
90+
parsed.error.message,
91+
event,
92+
);
8593
} else {
94+
// Has jsonrpc: "2.0" but is otherwise malformed — surface as a real
95+
// protocol error.
8696
console.error("Failed to parse message", parsed.error.message, event);
8797
this.onerror?.(
8898
new Error(

0 commit comments

Comments
 (0)