jackwener/OpenCLI · error · AuthRequiredError

LinkedIn JSESSIONID cookie not found. Please sign in to Link

Error message

LinkedIn JSESSIONID cookie not found. Please sign in to LinkedIn.

What it means

getCsrf reads browser cookies for www.linkedin.com and extracts JSESSIONID to build the CSRF token for Sales Navigator API calls. If no JSESSIONID cookie exists, it throws AuthRequiredError: there is no authenticated LinkedIn session in the browser, so no API request can be signed.

Source

Thrown at clis/linkedin/salesnav-message.js:186

    throw new CommandExecutionError(`${label} returned malformed response`);
  }
  if (requireJson && (!result.json || typeof result.json !== 'object' || Array.isArray(result.json))) {
    throw new CommandExecutionError(`${label} returned malformed response`, 'missing_json');
  }
  return result;
}

function salesPageShowsSentMessage(text, recipientName) {
  const normalizedText = normalizeWhitespace(text);
  const firstName = normalizeWhitespace(recipientName).split(' ')[0];
  return normalizedText.includes('You sent a Sales Navigator message')
    && (!firstName || normalizedText.includes(firstName));
}

async function getCsrf(page) {
  const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });
  const jsession = cookies.find((c) => c.name === 'JSESSIONID')?.value;
  if (!jsession) throw new AuthRequiredError(LINKEDIN_DOMAIN, 'LinkedIn JSESSIONID cookie not found. Please sign in to LinkedIn.');
  return jsession.replace(/^\"|\"$/g, '');
}

async function resolveRecipient(page, parsed, csrf) {
  if (!parsed) throw new ArgumentError('--recipient must be a Sales Navigator lead URL, Sales Navigator profile URL, LinkedIn /in/ URL, or urn:li:fs_salesProfile:(...)');
  if (parsed.entityUrn && parsed.authType && parsed.authToken) return parsed;

  await page.goto(`https://www.linkedin.com/sales/lead/${encodeURIComponent(parsed.profileId)}`);
  await page.wait(6);
  const probe = unwrapEvaluateResult(await page.evaluate(String.raw`(() => {
    const href = location.href;
    const text = document.body ? document.body.innerText : '';
    const resourceUrns = Array.from(performance.getEntriesByType('resource'))
      .map((entry) => entry.name)
      .filter((name) => name.includes('/sales-api/salesApiProfiles/'))
      .slice(-20);
    return { href, text: text.slice(0, 1000), resourceUrns };
  })()`));

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log into linkedin.com in the automation browser before running salesnav-message
  2. Persist and restore cookies/storageState between runs
  3. Check the account wasn't signed out remotely (password change, security event)
  4. Verify you are attached to a browser session (this command requires one)

Example fix

// before: fresh browser, no cookies
const page = await browser.newPage();
await cli.run('linkedin', 'salesnav-message', ...);
// after
const page = await browser.newPage();
await restoreSession(page); // or manual login
await cli.run('linkedin', 'salesnav-message', ...);
Defensive patterns

Strategy: validation

Validate before calling

const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });
if (!cookies.some((c) => c.name === 'JSESSIONID')) {
  throw new Error('No JSESSIONID: sign in to LinkedIn before running salesnav-message');
}

Type guard

const hasJsessionid = (cookies) => Array.isArray(cookies) && cookies.some((c) => c.name === 'JSESSIONID' && typeof c.value === 'string' && c.value.length > 0);

Try / catch

try {
  await cli.run('linkedin', 'salesnav-message', page, args);
} catch (err) {
  if (/JSESSIONID cookie not found/.test(err.message)) {
    await interactiveLogin(page); // then retry
  } else throw err;
}

Prevention

When it happens

Trigger: page.getCookies({url:'https://www.linkedin.com'}) returns no cookie named JSESSIONID — the browser profile was never logged in, cookies were cleared, or the session was logged out.

Common situations: Fresh headless browser with empty cookie jar; automated cookie cleanup between runs; LinkedIn invalidated the session (password change, 'sign out of all devices'); running in CI without restoring saved cookies.

Related errors


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