jackwener/OpenCLI · error · CommandExecutionError

LinkedIn messengerMessages API returned an unexpected respon

Error message

LinkedIn messengerMessages API returned an unexpected response: ${fetched?.error || 'no data'}

What it means

The in-page fetch of the messengerMessages API returned a response the parser cannot use: no data, an error field, or a missing/non-array pages property. This is a contract violation of the expected {pages: [...]} response shape, thrown as CommandExecutionError with the underlying error or 'no data'.

Source

Thrown at clis/linkedin/thread-snapshot.js:359

    const actualUrl = canonicalizeLinkedInThreadUrl(discovery.url || '');
    if (threadUrl && actualUrl && threadUrl !== actualUrl) {
      throw new CommandExecutionError('LinkedIn thread-snapshot blocked: thread_url_mismatch', `Expected ${threadUrl}; actual ${actualUrl}`);
    }
    if (maxScrolls >= 4 && discovery.scrollAttempts >= maxScrolls && discovery.scrollStable === false) {
      throw new CommandExecutionError('LinkedIn thread history did not stabilize before --max-scrolls; refusing to return a partial snapshot.');
    }

    const apiUrls = validateThreadApiUrls(discovery.apiUrls, threadUrl);
    const csrf = await requireLinkedInCookie(page, 'LinkedIn thread-snapshot');
    const fetched = unwrapEvaluateResult(
      await page.evaluate(buildFetchThreadPagesScript(apiUrls, csrf)),
    );
    if (fetched?.authRequired) {
      throw new AuthRequiredError(LINKEDIN_DOMAIN, `LinkedIn messengerMessages API authentication failed: ${fetched.error}`);
    }
    if (!fetched || fetched.error || !Array.isArray(fetched.pages)) {
      throw new CommandExecutionError(`LinkedIn messengerMessages API returned an unexpected response: ${fetched?.error || 'no data'}`);
    }

    const parsed = parseThreadPages(fetched.pages);
    const recipient = parsed.recipientNames.join(', ');
    const latestMessageText = parsed.messages[parsed.messages.length - 1]?.text || '';
    const normalized = {
      url: actualUrl || threadUrl,
      title: normalizeWhitespace(discovery.title),
      headerNames: parsed.recipientNames,
      latestMessageText,
      messages: parsed.messages,
      messageCount: parsed.messages.length,
      authRequired: false,
      extractedAt: new Date().toISOString(),
      maxScrolls,
      source: 'linkedin-messengerMessages',
    };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Read the ${fetched?.error} detail in the message to identify the underlying API failure and address it
  2. Retry the command after confirming the thread loads in the normal LinkedIn web UI
  3. Refresh the page/session (cookies, CSRF token) and retry, ruling out a transient block
  4. If it persists after a confirmed UI-side schema change, update the CLI to the latest version or file an issue — the parse contract may be stale
Defensive patterns

Strategy: retry

Validate before calling

// Confirm the thread renders in the normal UI before invoking
await page.goto(threadUrl); await page.wait(10);
const ok = await page.evaluate(() => !!document.querySelector('.msg-thread, [data-view-name="thread"]'));
if (!ok) throw new Error('Thread not rendered; fix session/page before snapshot');

Try / catch

try {
  await threadSnapshot({ threadUrl });
} catch (e) {
  if (String(e.message).includes('unexpected response')) {
    await page.reload(); await page.wait(5);
    return threadSnapshot({ threadUrl }); // single retry after refresh
  } else throw e;
}

Prevention

When it happens

Trigger: messengerMessages API returning an HTML error page, a JSON body without a pages array (LinkedIn schema change), an empty/blocked response, or fetched being null after unwrapEvaluateResult.

Common situations: LinkedIn silently changing the messengerMessages response schema; thread deleted mid-fetch returning an error payload; network failure or anti-bot interstitial replacing the API response; LinkedIn CDN serving an error JSON.

Related errors


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