devtools
devtools copied to clipboard
SyntaxError: "[Object Object]" is not valid JSON when parsing event.data
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
- Trigger a message event where event.data is an object instead of a JSON string.
- The code tries to parse event.data using SuperJSON.parse.
- 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