jackwener/OpenCLI · error · CommandExecutionError

LinkedIn search returned an unexpected response

Error message

LinkedIn search returned an unexpected response

What it means

If the page-context fetch returns null/undefined or an object without batch.error, fetchJobCards cannot interpret the response and throws this generic CommandExecutionError. It is a fallback for 'response shape we did not anticipate', e.g. evaluate serialization failures or the script returning undefined.

Source

Thrown at clis/linkedin/search.js:280

      });
      if (res.status === 401 || res.status === 403) {
        const text = await res.text();
        return {
          authRequired: true,
          error: 'LinkedIn API authentication failed: HTTP ' + res.status + ' ' + text.slice(0, 200)
        };
      }
      if (!res.ok) {
        const text = await res.text();
        return { error: 'LinkedIn API error: HTTP ' + res.status + ' ' + text.slice(0, 200) };
      }
      return res.json();
    })()`);
        if (!batch || batch.error) {
            if (batch?.authRequired) {
                throw new AuthRequiredError(LINKEDIN_DOMAIN, batch.error);
            }
            throw new CommandExecutionError(batch?.error || 'LinkedIn search returned an unexpected response');
        }
        const elements = Array.isArray(batch?.elements) ? batch.elements : [];
        if (elements.length === 0)
            break;
        for (const element of elements) {
            const card = element?.jobCardUnion?.jobPostingCard;
            if (!card)
                continue;
            // Extract job ID from URN fields
            const jobId = [card.jobPostingUrn, card.jobPosting?.entityUrn, card.entityUrn]
                .filter(Boolean)
                .map(s => String(s).match(/(\d+)/)?.[1])
                .find(Boolean) ?? '';
            // Extract listed date
            const listedItem = (card.footerItems || []).find((i) => i?.type === 'LISTED_DATE' && i?.timeAt);
            const listed = listedItem?.timeAt ? new Date(listedItem.timeAt).toISOString().slice(0, 10) : '';
            allJobs.push({
                title: card.jobPostingTitle || card.title?.text || '',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command — this is frequently a transient evaluation failure; ensure the browser stays open and no navigation occurs during the search.
  2. Check that the browser session is healthy: reload linkedin.com/jobs in the automation browser and confirm it renders normally (no crash, no challenge page).
  3. Update the CLI and browser automation dependencies — evaluate serialization behavior can differ across versions.
  4. If reproducible, debug by logging what page.evaluate returns for the Voyager call; the response shape may need a new handling branch.

Example fix

// before (batch came back undefined because tab closed mid-fetch)
const batch = await page.evaluate(fetchScript);
// after — keep the page alive and validate before continuing
await page.bringToFront();
const batch = await page.evaluate(fetchScript);
if (!batch) throw new Error('evaluate returned nothing — is the tab still open?');
Defensive patterns

Strategy: retry

Validate before calling

null

Type guard

const isUnexpectedLinkedInResponse = (e) =>
  e instanceof Error && /LinkedIn search returned an unexpected response/.test(e.message);

Try / catch

async function searchWithRetry(args, tries = 2) {
  for (let i = 0; i < tries; i++) {
    try { return await run(['linkedin', 'search', ...args]); }
    catch (e) {
      if (isUnexpectedLinkedInResponse(e) && i < tries - 1) {
        await new Promise(r => setTimeout(r, 3000));
        continue;
      }
      throw e;
    }
  }
}

Prevention

When it happens

Trigger: page.evaluate on the Voyager fetch returns a falsy value (browser context destroyed mid-fetch, navigation, crashed renderer) or a non-error object lacking `elements` — the guard `if (!batch || batch.error)` falls through to the message 'LinkedIn search returned an unexpected response'.

Common situations: Page navigated or tab closed while the fetch was in flight; browser crashed or was rate-limited into an interstitial that broke evaluate; anti-bot tooling neutralizing in-page fetch; CLI/browser version mismatch corrupting evaluate return serialization.

Related errors


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