jackwener/OpenCLI · error · CommandExecutionError

LinkedIn cookie lookup failed: ${error?.message || error}

Error message

LinkedIn cookie lookup failed: ${error?.message || error}

What it means

requireLinkedInCookie calls page.getCookies({url:'https://www.linkedin.com'}) through the browser automation driver; if that call itself fails (browser closed, driver error, protocol failure), it wraps the underlying cause in CommandExecutionError with the original message appended. This distinguishes driver-level failure from 'no cookie found'.

Source

Thrown at clis/linkedin/shared.js:125

  if (!value) throw new ArgumentError(`${label} is required`);
  return value;
}

export function parseLimit(value, fallback, max) {
  if (value === undefined || value === null || value === '') return fallback;
  const parsed = Number(value);
  if (!Number.isInteger(parsed) || parsed < 1 || parsed > max) {
    throw new ArgumentError(`--limit must be an integer between 1 and ${max}`);
  }
  return parsed;
}

export async function requireLinkedInCookie(page, context) {
  let cookies;
  try {
    cookies = await page.getCookies({ url: 'https://www.linkedin.com' });
  } catch (error) {
    throw new CommandExecutionError(`LinkedIn cookie lookup failed: ${error?.message || error}`);
  }
  if (!Array.isArray(cookies)) {
    throw new CommandExecutionError('LinkedIn cookie lookup returned malformed payload');
  }
  const jsession = cookies.find((c) => c.name === 'JSESSIONID')?.value;
  if (!jsession) {
    throw new AuthRequiredError(LINKEDIN_DOMAIN, `${context} requires an active signed-in LinkedIn browser session.`);
  }
  return jsession.replace(/^"|"$/g, '');
}

export function buildAuthProbeScript() {
  return String.raw`(() => {
    const text = [
      window.location.href || '',
      document.title || '',
      document.body ? (document.body.innerText || '').slice(0, 4000) : '',
    ].join('\n');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Ensure the browser session is launched and the page is open before calling csrf.
  2. Check the embedded cause message (`error?.message || error`) for the driver-level problem and fix that first.
  3. Restart the browser/session and rerun the command.
  4. Pin compatible versions of the automation driver/browser; update the CLI if getCookies signature changed.

Example fix

// before
const page = await browser.newPage();
await page.close();
await csrf({ page }); // getCookies on closed context
// after
const page = await browser.newPage();
await csrf({ page }); // keep page open until after cookie lookup
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify the page is live before cookie lookup
if (!page || page.isClosed?.()) throw new Error('Browser page is closed; relaunch before csrf lookup');

Type guard

function isUsablePage(p) {
  return !!p && typeof p.getCookies === 'function' && !(typeof p.isClosed === 'function' && p.isClosed());
}

Try / catch

let jsession;
try {
  jsession = await requireLinkedInCookie(page, 'csrf');
} catch (e) {
  if (e instanceof CommandExecutionError && e.message.startsWith('LinkedIn cookie lookup failed')) {
    console.error('Driver error during getCookies; relaunching browser...', e.message);
    page = await relaunchBrowser();
  } else throw e;
}

Prevention

When it happens

Trigger: The browser page/context was closed before csrf ran, the automation client disconnected, the driver rejects getCookies for the given URL, or a Playwright/Puppeteer version/protocol mismatch breaks the cookies API.

Common situations: Long-running scripts where the browser crashed or was killed; headless browser in CI that exited early; version drift between the CLI and installed browser/driver.

Related errors


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