{"record":{"id":"2f524efeec2ea024","repo":"jackwener/OpenCLI","slug":"xiaohongshu-creator-note-detail-malformed-capture","errorCode":null,"errorMessage":"xiaohongshu creator-note-detail: malformed capture for ${suffix}","messagePattern":"xiaohongshu creator-note-detail: malformed capture for (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/creator-note-detail.js","lineNumber":303,"sourceCode":"    }\n    if (endpoint.key === 'noteBase') {\n        assertOptionalPlainObject(payload, 'hour', suffix);\n        assertOptionalPlainObject(payload, 'day', suffix);\n    }\n    if (endpoint.key === 'audienceSource') {\n        assertOptionalArray(payload, 'source', suffix);\n    }\n    if (endpoint.key === 'audienceSourceDetail') {\n        for (const key of ['gender', 'age', 'city', 'interest']) {\n            assertOptionalArray(payload, key, suffix);\n        }\n    }\n    return payload;\n}\nfunction parseCapturedJson(capture, endpoint) {\n    const suffix = endpoint.suffix;\n    if (!capture || typeof capture !== 'object') {\n        throw new CommandExecutionError(`xiaohongshu creator-note-detail: malformed capture for ${suffix}`);\n    }\n    if (capture.ok !== true) {\n        throw new CommandExecutionError(`xiaohongshu creator-note-detail: signed API ${suffix} returned HTTP ${capture.status ?? 'non-2xx'}`);\n    }\n    if (typeof capture.body !== 'string') {\n        throw new CommandExecutionError(`xiaohongshu creator-note-detail: signed API ${suffix} returned a non-text body`);\n    }\n    try {\n        const envelope = JSON.parse(capture.body);\n        const payload = isPlainObject(envelope) && Object.hasOwn(envelope, 'data') ? envelope.data : envelope;\n        return validateCapturedPayload(payload, endpoint);\n    }\n    catch {\n        throw new CommandExecutionError(`xiaohongshu creator-note-detail: signed API ${suffix} returned invalid JSON or payload shape`);\n    }\n}\n// Capture the dashboard's signed datacenter/note responses on window.__xhsCapture\n// since a direct fetch() from page.evaluate bypasses the x-s signing and gets 406.","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/creator-note-detail.js#L285-L321","documentation":"parseCapturedJson validates a network capture record before parsing its body. The capture must be an object with ok === true and a string body; when the capture itself is null, a primitive, or otherwise not an object, this error reports 'malformed capture' for the endpoint suffix, meaning the interception layer never produced a usable record.","triggerScenarios":"captureNoteDetailPayload's page capture returned null/undefined (the response never matched the listener or the wait timed out) or returned a non-object record; validateCapturedJson is then invoked with that bad capture.","commonSituations":"The signed API request never fired (page blocked, navigation too fast); response listener registered after the request completed; capture object shape changed in the driver layer; page.evaluate/page.wait wrapper returns null on timeout.","solutions":["Retry — the request may simply not have been captured this run","Ensure response listeners are attached before navigation and wait long enough for all signed endpoints to fire","Log which endpoint suffix failed and inspect network traffic to confirm the request occurred","Check whether risk control/login wall prevented the creator API calls entirely (see SECURITY_BLOCK/AuthRequiredError)"],"exampleFix":"// before\nif (!capture || typeof capture !== 'object') {\n    throw new CommandExecutionError(`... malformed capture for ${suffix}`);\n}\n// after\nif (!capture || typeof capture !== 'object') {\n    // one retry: reload and re-capture before failing\n    capture = await captureNoteDetailPayload(page, endpoint, { retry: true });\n    if (!capture || typeof capture !== 'object') {\n        throw new CommandExecutionError(`... malformed capture for ${suffix}`);\n    }\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":"const isCapture = (c) => c !== null && typeof c === 'object' && c.ok === true && typeof c.body === 'string';","tryCatchPattern":"try {\n  const detail = await cli.creatorNoteDetail(noteId);\n} catch (err) {\n  if (err.message.includes('malformed capture for')) {\n    await sleep(3000);\n    return cli.creatorNoteDetail(noteId); // capture listeners may have missed the request\n  }\n  throw err;\n}","preventionTips":["Register network listeners before navigation","Wait long enough for all signed endpoints to respond","Ensure the page is not blocked/login-walled before capturing","Add one automatic reload-and-recapture attempt for missing endpoints"],"tags":["network-capture","scraping","signed-api","interception"],"backgroundTag":"network-capture-missing","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}