jackwener/OpenCLI · error · CommandExecutionError

xiaohongshu creator-note-detail: malformed signed datacenter

Error message

xiaohongshu creator-note-detail: malformed signed datacenter/note capture buffer

What it means

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.

Source

Thrown at clis/xiaohongshu/creator-note-detail.js:400

    await page.evaluate(`(() => {
    const target = '/statistics/note-detail?noteId=' + ${JSON.stringify(noteId)};
    history.pushState({}, '', target);
    window.dispatchEvent(new PopStateEvent('popstate'));
  })()`);
    const wantedSuffixes = DETAIL_API_ENDPOINTS.map((endpoint) => endpoint.suffix);
    let captureMap = {};
    for (let i = 0; i < CAPTURE_POLL_ATTEMPTS; i++) {
        await page.wait(CAPTURE_POLL_INTERVAL_S);
        let raw;
        try {
            raw = await page.evaluate('JSON.stringify(window.__xhsCapture || {})');
            captureMap = typeof raw === 'string' ? JSON.parse(raw) : {};
        }
        catch {
            throw new CommandExecutionError('xiaohongshu creator-note-detail: failed to read signed datacenter/note capture buffer');
        }
        if (!captureMap || typeof captureMap !== 'object' || Array.isArray(captureMap)) {
            throw new CommandExecutionError('xiaohongshu creator-note-detail: malformed signed datacenter/note capture buffer');
        }
        const captured = wantedSuffixes.filter((suffix) => findCapturedUrl(captureMap, suffix));
        if (captured.length === wantedSuffixes.length)
            break;
    }
    const payload = {};
    for (const endpoint of DETAIL_API_ENDPOINTS) {
        const matchUrl = findCapturedUrl(captureMap, endpoint.suffix);
        if (!matchUrl)
            continue;
        payload[endpoint.key] = parseCapturedJson(captureMap[matchUrl], endpoint);
    }
    return Object.keys(payload).length > 0 ? payload : null;
}
async function captureNoteDetailDomData(page) {
    const result = await page.evaluate(`() => {
    const norm = (value) => (value || '').trim();
    const sections = Array.from(document.querySelectorAll('.shell-container')).map((container) => {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use a fresh tab / restart the run so installXhsFetchCaptureHook resets window.__xhsCapture = {} and reinstalls the hook.
  2. Disable interfering browser extensions that might redefine window globals.
  3. Ensure you are not manually assigning to window.__xhsCapture in custom page.evaluate scripts.
  4. If reusing a persistent tab, clear the buffer (evaluate `window.__xhsCapture = {}`) before invoking the command.
  5. Update the CLI if a recent Xiaohongshu dashboard change conflicts with the global name.

Example fix

// before
await page.evaluate('window.__xhsCapture = window.__xhsCapture || []'); // wrong shape
// after
await page.evaluate('window.__xhsCapture = {}; window.__xhsCaptureInstalled = false;');
const rows = await run('xiaohongshu creator-note-detail', { 'note-id': id });
Defensive patterns

Strategy: validation

Validate before calling

await page.evaluate("if (typeof window.__xhsCapture !== 'object' || Array.isArray(window.__xhsCapture) || window.__xhsCapture === null) window.__xhsCapture = {};");

Type guard

function isValidCaptureMap(v) {
  return typeof v === 'object' && v !== null && !Array.isArray(v);
}

Try / catch

try {
  return await run('xiaohongshu creator-note-detail', { 'note-id': id });
} catch (e) {
  if (/malformed signed .* capture buffer/.test(e.message)) {
    await resetCaptureBuffer(page); // evaluate: window.__xhsCapture = {}
    return await run('xiaohongshu creator-note-detail', { 'note-id': id });
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/3181ba2a902beedd. Report an issue: GitHub.