devtools icon indicating copy to clipboard operation
devtools copied to clipboard

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

Open CorgiTT opened this issue 4 months ago • 0 comments

Image

Description When handling a message event, the following error occurs: SyntaxError: "[Object Object]" is not valid JSON

This happens at the line: const parsed = SuperJSON.parse(event.data);

Details

  • File: index.js
  • Line: 5924
  • Stack: Vue DevTools, Vite, SuperJSON From the debug panel, event.data is sometimes an object, not a JSON string. When SuperJSON.parse is called on an object, it throws the above error.

Example of problematic data:

event.data = {
  payload: '{"json":{"event":{"event":"shutdown"}}}',
  source: "proxy->server"
}

Steps to Reproduce

  1. Trigger a message event where event.data is an object instead of a JSON string.
  2. The code tries to parse event.data using SuperJSON.parse.
  3. The error is thrown: "[Object Object]" is not valid JSON.

Expected Behavior The code should check if event.data is a string before parsing, or handle objects appropriately.

Environment

  • OS: macOS m3
  • Browser: 137.0.7151.120 (arm64)
  • Project: Vue DevTools + Vite

CorgiTT avatar Jun 26 '25 10:06 CorgiTT