Skip to content

fix: preserve raw request data to fix [object Object] display issue#61

Merged
GrinZero merged 3 commits intoGrinZero:mainfrom
BAIXIONGSODA:fix/post-data
Apr 20, 2026
Merged

fix: preserve raw request data to fix [object Object] display issue#61
GrinZero merged 3 commits intoGrinZero:mainfrom
BAIXIONGSODA:fix/post-data

Conversation

@BAIXIONGSODA
Copy link
Copy Markdown

Problem

When sending HTTP requests with text/plain Content-Type but JSON body (e.g., some logging SDKs), the DevTools Network panel shows [object Object] instead of the actual request payload.

Root Cause

In request.ts, the code unnecessarily parses the request data with JSON.parse(), converting the string to an object. Later in index.ts, when building the CDP postData field, it only re-serializes for application/json Content-Type, leaving text/plain requests with an object that becomes [object Object].

Solution

  • Remove unnecessary JSON.parse() in request.ts, keep raw data format
  • Simplify postData handling in index.ts to always use .toString()
  • Let Chrome DevTools handle JSON parsing and display (which it does correctly)

Changes

  • packages/network-debugger/src/core/request.ts: Remove JSON.parse, preserve original data
  • packages/network-debugger/src/fork/module/network/index.ts: Simplify to request.requestData.toString()

- Remove unnecessary JSON.parse in request.ts, keep original data format
- Simplify postData handling in index.ts, let DevTools parse JSON itself
- Fixes issue where text/plain requests with JSON body showed [object Object]
@GrinZero
Copy link
Copy Markdown
Owner

👋 Hello, can you post some screenshots and test cases? I'm not sure which case needs to be fixed like this

@GrinZero
Copy link
Copy Markdown
Owner

image

I tried to start the koa-esm project and requested http://127.0.0.1:3001/post. This is the result.

@GrinZero
Copy link
Copy Markdown
Owner

I don't know what case you are using.
For the current koa-esm case, it can be fixed this way

  • packages/network-debugger/src/fork/module/network/index.ts
         postData: (() => {
                  const data = request.requestData
                  if (Buffer.isBuffer(data)) {
                    return data.toString('utf-8')
                  }
                  if (data?. type === 'Buffer' && Array.isArray(data.data)) {
                    return Buffer.from(data.data).toString('utf-8')
                  }
                  if (typeof data === 'string') {
                    return data
                  }
                  return JSON.stringify(data)
                })()

- Remove MAX_REQUEST_DATA_SIZE limit to capture complete request data
- Convert Buffer/object to string in write() to avoid IPC serialization issues
- Accumulate multiple write calls for multipart/form-data support
- Add test cases for various POST body types (text/plain, form, buffer)
@BAIXIONGSODA
Copy link
Copy Markdown
Author

BAIXIONGSODA commented Apr 17, 2026

感谢指出这个问题!

本次修复主要做了以下改动:

  • write() 时将 Buffer/对象直接转换为字符串,避免 IPC 序列化导致的 [object Object] 问题
  • 移除了 MAX_REQUEST_DATA_SIZE 限制,完整累加所有 write 调用的数据(支持 multipart/form-data 等场景)
  • 新增了多种 POST body 类型的测试用例(text/plain、form-urlencoded、buffer)

麻烦再帮忙检查一下是否还有其他问题,感谢!


Thanks for pointing out this issue!

This fix includes the following changes:

  • Convert Buffer/object to string directly in write() to avoid IPC serialization causing [object Object] issue
  • Remove MAX_REQUEST_DATA_SIZE limit, accumulate all write call data completely (support multipart/form-data and other scenarios)
  • Add test cases for various POST body types (text/plain, form-urlencoded, buffer)

Please help check if there are any other issues. Thanks!

@GrinZero GrinZero merged commit 797cfc4 into GrinZero:main Apr 20, 2026
1 check passed
@GrinZero
Copy link
Copy Markdown
Owner

has been merged. By the way, can SSE also be optimized?

@BAIXIONGSODA
Copy link
Copy Markdown
Author

I'll work on it today 🌹

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.

2 participants