{"record":{"id":"3181ba2a902beedd","repo":"jackwener/OpenCLI","slug":"xiaohongshu-creator-note-detail-malformed-signed","errorCode":null,"errorMessage":"xiaohongshu creator-note-detail: malformed signed datacenter/note capture buffer","messagePattern":"xiaohongshu creator-note-detail: malformed signed datacenter/note capture buffer","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/creator-note-detail.js","lineNumber":400,"sourceCode":"    await page.evaluate(`(() => {\n    const target = '/statistics/note-detail?noteId=' + ${JSON.stringify(noteId)};\n    history.pushState({}, '', target);\n    window.dispatchEvent(new PopStateEvent('popstate'));\n  })()`);\n    const wantedSuffixes = DETAIL_API_ENDPOINTS.map((endpoint) => endpoint.suffix);\n    let captureMap = {};\n    for (let i = 0; i < CAPTURE_POLL_ATTEMPTS; i++) {\n        await page.wait(CAPTURE_POLL_INTERVAL_S);\n        let raw;\n        try {\n            raw = await page.evaluate('JSON.stringify(window.__xhsCapture || {})');\n            captureMap = typeof raw === 'string' ? JSON.parse(raw) : {};\n        }\n        catch {\n            throw new CommandExecutionError('xiaohongshu creator-note-detail: failed to read signed datacenter/note capture buffer');\n        }\n        if (!captureMap || typeof captureMap !== 'object' || Array.isArray(captureMap)) {\n            throw new CommandExecutionError('xiaohongshu creator-note-detail: malformed signed datacenter/note capture buffer');\n        }\n        const captured = wantedSuffixes.filter((suffix) => findCapturedUrl(captureMap, suffix));\n        if (captured.length === wantedSuffixes.length)\n            break;\n    }\n    const payload = {};\n    for (const endpoint of DETAIL_API_ENDPOINTS) {\n        const matchUrl = findCapturedUrl(captureMap, endpoint.suffix);\n        if (!matchUrl)\n            continue;\n        payload[endpoint.key] = parseCapturedJson(captureMap[matchUrl], endpoint);\n    }\n    return Object.keys(payload).length > 0 ? payload : null;\n}\nasync function captureNoteDetailDomData(page) {\n    const result = await page.evaluate(`() => {\n    const norm = (value) => (value || '').trim();\n    const sections = Array.from(document.querySelectorAll('.shell-container')).map((container) => {","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/creator-note-detail.js#L382-L418","documentation":"captureNoteDetailPayload throws this CommandExecutionError when the value read from window.__xhsCapture is not a plain object (null, an array, or another non-object type). The hook always initializes the buffer to {}, so a malformed buffer means something else on the page replaced or shadowed window.__xhsCapture.","triggerScenarios":"A site script, extension, or earlier automation run overwrote window.__xhsCapture with a non-object (array/null/string); the hook was not actually installed on this tab so an unrelated global of the same name exists; a stale capture from a previous run left an unexpected shape.","commonSituations":"Sharing one tab across multiple CLI runs without resetting the buffer; extensions that proxy globals; running the command against a page where the hook's reset `window.__xhsCapture = {}` never executed because installXhsFetchCaptureHook failed silently.","solutions":["Use a fresh tab / restart the run so installXhsFetchCaptureHook resets window.__xhsCapture = {} and reinstalls the hook.","Disable interfering browser extensions that might redefine window globals.","Ensure you are not manually assigning to window.__xhsCapture in custom page.evaluate scripts.","If reusing a persistent tab, clear the buffer (evaluate `window.__xhsCapture = {}`) before invoking the command.","Update the CLI if a recent Xiaohongshu dashboard change conflicts with the global name."],"exampleFix":"// before\nawait page.evaluate('window.__xhsCapture = window.__xhsCapture || []'); // wrong shape\n// after\nawait page.evaluate('window.__xhsCapture = {}; window.__xhsCaptureInstalled = false;');\nconst rows = await run('xiaohongshu creator-note-detail', { 'note-id': id });","handlingStrategy":"validation","validationCode":"await page.evaluate(\"if (typeof window.__xhsCapture !== 'object' || Array.isArray(window.__xhsCapture) || window.__xhsCapture === null) window.__xhsCapture = {};\");","typeGuard":"function isValidCaptureMap(v) {\n  return typeof v === 'object' && v !== null && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  return await run('xiaohongshu creator-note-detail', { 'note-id': id });\n} catch (e) {\n  if (/malformed signed .* capture buffer/.test(e.message)) {\n    await resetCaptureBuffer(page); // evaluate: window.__xhsCapture = {}\n    return await run('xiaohongshu creator-note-detail', { 'note-id': id });\n  }\n  throw e;\n}","preventionTips":["Run in a fresh tab so installXhsFetchCaptureHook resets the buffer cleanly.","Disable extensions that redefine window globals.","Do not write to window.__xhsCapture from your own scripts.","Clear the buffer between repeated runs on a persistent tab.","Reinstall the hook (rerun the command) if a previous run errored mid-way."],"tags":["capture-hook","browser-automation","xiaohongshu","global-state"],"backgroundTag":"capture-buffer-malformed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}