From f2f001ec74441db8913946eeb693ae7f2c8b9b37 Mon Sep 17 00:00:00 2001 From: wangxiang06 Date: Fri, 17 Apr 2026 11:57:37 +0800 Subject: [PATCH 1/2] fix: preserve raw request data to fix [object Object] display issue - 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] --- packages/network-debugger/src/core/request.ts | 8 ++------ .../network-debugger/src/fork/module/network/index.ts | 6 +----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/network-debugger/src/core/request.ts b/packages/network-debugger/src/core/request.ts index c6174ab..8611331 100644 --- a/packages/network-debugger/src/core/request.ts +++ b/packages/network-debugger/src/core/request.ts @@ -22,12 +22,8 @@ function proxyClientRequestFactory( ) { const actualFn = actualRequest.write actualRequest.write = (data: any) => { - try { - requestDetail.requestData = JSON.parse(data.toString()) - } catch (err) { - requestDetail.requestData = data - } - + // 保持原始数据格式,由 DevTools 自行解析展示 + requestDetail.requestData = data return actualFn.bind(actualRequest)(data) } diff --git a/packages/network-debugger/src/fork/module/network/index.ts b/packages/network-debugger/src/fork/module/network/index.ts index 4811469..8632eb6 100644 --- a/packages/network-debugger/src/fork/module/network/index.ts +++ b/packages/network-debugger/src/fork/module/network/index.ts @@ -180,11 +180,7 @@ export const networkPlugin = createPlugin('network', ({ devtool, core }) => { initialPriority: 'High', mixedContentType: 'none', ...(request.requestData - ? { - postData: contentType?.includes('application/json') - ? JSON.stringify(request.requestData) - : request.requestData - } + ? { postData: request.requestData.toString() } : {}) }, timestamp: devtool.timestamp, From 7bfc5404481d824b90ae8b11be93c032e1a0ec98 Mon Sep 17 00:00:00 2001 From: wangxiang06 Date: Fri, 17 Apr 2026 17:24:02 +0800 Subject: [PATCH 2/2] fix: convert request data to string at source and accumulate all writes - 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) --- apps/koa-esm/src/index.js | 39 +++++++++++++++++++ packages/network-debugger/src/core/request.ts | 21 +++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/apps/koa-esm/src/index.js b/apps/koa-esm/src/index.js index 218b159..8d1ad43 100644 --- a/apps/koa-esm/src/index.js +++ b/apps/koa-esm/src/index.js @@ -77,6 +77,45 @@ router.get('/fetch', async (ctx) => { ctx.body = data }) +// Test case 1: text/plain + JSON body +router.get('/post-text-plain', async (ctx) => { + const res = await axios.post( + 'https://jsonplaceholder.typicode.com/posts', + JSON.stringify({ title: 'foo', body: 'bar', userId: 1 }), + { headers: { 'Content-Type': 'text/plain' } } + ) + ctx.body = res.data +}) + +// Test case 2: application/x-www-form-urlencoded +router.get('/post-form', async (ctx) => { + const res = await axios.post( + 'https://jsonplaceholder.typicode.com/posts', + 'title=foo&body=bar&userId=1', + { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } + ) + ctx.body = res.data +}) + +// Test case 3: pure text body +router.get('/post-pure-text', async (ctx) => { + const res = await axios.post( + 'https://jsonplaceholder.typicode.com/posts', + 'This is a plain text message', + { headers: { 'Content-Type': 'text/plain' } } + ) + ctx.body = res.data +}) + +// Test case 4: Buffer body +router.get('/post-buffer', async (ctx) => { + const buffer = Buffer.from(JSON.stringify({ title: 'buffer', body: 'test', userId: 1 })) + const res = await axios.post('https://jsonplaceholder.typicode.com/posts', buffer, { + headers: { 'Content-Type': 'application/json' } + }) + ctx.body = res.data +}) + app.use(router.routes()) app.listen(3001) diff --git a/packages/network-debugger/src/core/request.ts b/packages/network-debugger/src/core/request.ts index 8611331..a07b611 100644 --- a/packages/network-debugger/src/core/request.ts +++ b/packages/network-debugger/src/core/request.ts @@ -22,8 +22,25 @@ function proxyClientRequestFactory( ) { const actualFn = actualRequest.write actualRequest.write = (data: any) => { - // 保持原始数据格式,由 DevTools 自行解析展示 - requestDetail.requestData = data + // Convert to string at source to avoid IPC serialization issues + // Accumulate multiple writes (e.g., multipart/form-data) + let chunk: string + if (Buffer.isBuffer(data)) { + chunk = data.toString('utf-8') + } else if (typeof data === 'string') { + chunk = data + } else if (data != null) { + chunk = JSON.stringify(data) + } else { + chunk = '' + } + + if (requestDetail.requestData) { + requestDetail.requestData += chunk + } else { + requestDetail.requestData = chunk + } + return actualFn.bind(actualRequest)(data) }