Skip to content

fix(devtools-kit): guard SuperJSON.parse against non-string message payloads - #4

Open
arena-ai-coding-agent[bot] wants to merge 1 commit into
mainfrom
fix/issue-911-message-parse-guard
Open

fix(devtools-kit): guard SuperJSON.parse against non-string message payloads#4
arena-ai-coding-agent[bot] wants to merge 1 commit into
mainfrom
fix/issue-911-message-parse-guard

Conversation

@arena-ai-coding-agent

Copy link
Copy Markdown

Summary

DevTools' messaging channels call SuperJSON.parse(...) on incoming payloads. When a message event carries a non-string value (for example an object posted to a shared BroadcastChannel, or a window message whose payload is not a JSON string), parsing throws an uncaught:

SyntaxError: "[object Object]" is not valid JSON

This surfaces as an unhandled error in the console while DevTools is running (reported when event.data is an object instead of a JSON string).

Change

Guard the parse with a typeof … === 'string' check and ignore non-string payloads in the affected channels:

  • broadcast-channel/index.ts — only parse event.data when it is a string.
  • extension/server.ts — only parse event.data.payload when it is a string.
  • vite/client.ts and vite/server.ts — only parse the event payload when it is a string.

The iframe channels already defensively wrap parsing in a try/catch.

Tests

Full suite passes (85 tests) along with type-check, lint, and build.

Closes vuejs#911

…ayloads

When a message event carries a non-string payload (e.g. an object posted
to a shared BroadcastChannel, or a window message whose payload is not a
JSON string), SuperJSON.parse throws an uncaught
"SyntaxError: \"[object Object]\" is not valid JSON". This shows up in the
console as an unhandled error while DevTools is running.

Only attempt to parse the payload when it is a string, otherwise ignore the
message. This makes the broadcast, extension-server and Vite messaging
channels resilient to foreign messages on shared channels.

Closes vuejs#911
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SyntaxError: "[Object Object]" is not valid JSON when parsing event.data

1 participant