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>
This commit is contained in:
parent
a815f31392
commit
fd8cc978d4
1 changed files with 10 additions and 0 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in a new issue