{"record":{"id":"bc7cb09c96ea4fa8","repo":"jackwener/OpenCLI","slug":"linkedin-jsessionid-cookie-not-found-please-sign-bc7cb0","errorCode":null,"errorMessage":"LinkedIn JSESSIONID cookie not found. Please sign in to LinkedIn.","messagePattern":"LinkedIn JSESSIONID cookie not found\\. Please sign in to LinkedIn\\.","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/salesnav-message.js","lineNumber":186,"sourceCode":"    throw new CommandExecutionError(`${label} returned malformed response`);\n  }\n  if (requireJson && (!result.json || typeof result.json !== 'object' || Array.isArray(result.json))) {\n    throw new CommandExecutionError(`${label} returned malformed response`, 'missing_json');\n  }\n  return result;\n}\n\nfunction salesPageShowsSentMessage(text, recipientName) {\n  const normalizedText = normalizeWhitespace(text);\n  const firstName = normalizeWhitespace(recipientName).split(' ')[0];\n  return normalizedText.includes('You sent a Sales Navigator message')\n    && (!firstName || normalizedText.includes(firstName));\n}\n\nasync function getCsrf(page) {\n  const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });\n  const jsession = cookies.find((c) => c.name === 'JSESSIONID')?.value;\n  if (!jsession) throw new AuthRequiredError(LINKEDIN_DOMAIN, 'LinkedIn JSESSIONID cookie not found. Please sign in to LinkedIn.');\n  return jsession.replace(/^\\\"|\\\"$/g, '');\n}\n\nasync function resolveRecipient(page, parsed, csrf) {\n  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:(...)');\n  if (parsed.entityUrn && parsed.authType && parsed.authToken) return parsed;\n\n  await page.goto(`https://www.linkedin.com/sales/lead/${encodeURIComponent(parsed.profileId)}`);\n  await page.wait(6);\n  const probe = unwrapEvaluateResult(await page.evaluate(String.raw`(() => {\n    const href = location.href;\n    const text = document.body ? document.body.innerText : '';\n    const resourceUrns = Array.from(performance.getEntriesByType('resource'))\n      .map((entry) => entry.name)\n      .filter((name) => name.includes('/sales-api/salesApiProfiles/'))\n      .slice(-20);\n    return { href, text: text.slice(0, 1000), resourceUrns };\n  })()`));","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/salesnav-message.js#L168-L204","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Log into linkedin.com in the automation browser before running salesnav-message","Persist and restore cookies/storageState between runs","Check the account wasn't signed out remotely (password change, security event)","Verify you are attached to a browser session (this command requires one)"],"exampleFix":"// before: fresh browser, no cookies\nconst page = await browser.newPage();\nawait cli.run('linkedin', 'salesnav-message', ...);\n// after\nconst page = await browser.newPage();\nawait restoreSession(page); // or manual login\nawait cli.run('linkedin', 'salesnav-message', ...);","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });\nif (!cookies.some((c) => c.name === 'JSESSIONID')) {\n  throw new Error('No JSESSIONID: sign in to LinkedIn before running salesnav-message');\n}","typeGuard":"const hasJsessionid = (cookies) => Array.isArray(cookies) && cookies.some((c) => c.name === 'JSESSIONID' && typeof c.value === 'string' && c.value.length > 0);","tryCatchPattern":"try {\n  await cli.run('linkedin', 'salesnav-message', page, args);\n} catch (err) {\n  if (/JSESSIONID cookie not found/.test(err.message)) {\n    await interactiveLogin(page); // then retry\n  } else throw err;\n}","preventionTips":["Persist browser storage/cookies between runs","Verify login state (visit linkedin.com) before batch operations","Don't clear cookies between commands in the same session","Watch for remote sign-outs after password/security changes"],"tags":["auth","cookies","linkedin","jsessionid"],"backgroundTag":"missing-auth-cookie","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}