{"record":{"id":"a1b52b9d8c69eeb9","repo":"jackwener/OpenCLI","slug":"linkedin-jsessionid-cookie-not-found-please-sign-a1b52b","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":"critical","filePath":"clis/linkedin/salesnav-inbox.js","lineNumber":121,"sourceCode":"          accept: 'application/json',\n        },\n      });\n      const text = await res.text();\n      let json = null;\n      try { json = text ? JSON.parse(text) : null; } catch (_) { json = null; }\n      if (res.status === 401 || res.status === 403) return { authRequired: true, status: res.status, text };\n      if (!res.ok) return { error: 'HTTP ' + res.status, status: res.status, text, json };\n      return { status: res.status, json };\n    } catch (e) {\n      return { error: 'fetch failed: ' + ((e && e.message) || String(e)) };\n    }\n  })()`;\n}\n\nexport async 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\nexport async function fetchSalesnavJson(page, csrf, url, label) {\n  const result = unwrapEvaluateResult(await page.evaluate(fetchJsonScript(url, csrf)));\n  if (result?.authRequired) throw new AuthRequiredError(LINKEDIN_DOMAIN, `${label} authentication failed (HTTP ${result.status || 'auth_required'}).`);\n  if (result?.error || !result?.json) throw new CommandExecutionError(`${label} returned an unexpected response`, `${result?.error || 'no_json'}\\n${normalizeWhitespace(result?.text || '').slice(0, 500)}`);\n  return result.json;\n}\n\nexport async function fetchInboxRows(page, { limit = DEFAULT_LIMIT, maxPages = 30 } = {}) {\n  const csrf = await getCsrf(page);\n  const rows = [];\n  const seen = new Set();\n  let pageStartsAt = '';\n  let pagesFetched = 0;\n  let hasMorePages = false;\n  while (rows.length < limit && pagesFetched < maxPages) {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/salesnav-inbox.js#L103-L139","documentation":"This AuthRequiredError is thrown by getCsrf when the browser cookie jar for www.linkedin.com contains no JSESSIONID cookie. The JSESSIONID value doubles as the CSRF token for Sales Navigator API calls, so without it the session is not signed in and authenticated requests cannot be built.","triggerScenarios":"Calling fetchInboxRows (which calls getCsrf) while the Puppeteer/Playwright page is not signed in to LinkedIn, the session expired so LinkedIn dropped JSESSIONID, or cookies were cleared / a fresh profile context was used.","commonSituations":"Running the scraper with a fresh browser profile that never logged in; LinkedIn invalidated the session (password change, security logout); cookie expiry after long runs; using a context that blocks or partitions cookies.","solutions":["Sign in to LinkedIn in the automated page before running the command (persist storageState/cookies between runs)","Verify cookies exist: page.getCookies({ url: 'https://www.linkedin.com' }) should include JSESSIONID","Refresh or re-create the saved session if it expired","Ensure the browser context is not incognito/ephemeral without loading saved cookies"],"exampleFix":"// before\nconst page = await browser.newPage(); // no cookies\nawait fetchInboxRows(page);\n// after\nconst page = await browser.newPage();\nawait page.setCookie(...savedLinkedInCookies); // or restore storageState\nawait fetchInboxRows(page);","handlingStrategy":"try-catch","validationCode":"const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });\nif (!cookies.some((c) => c.name === 'JSESSIONID')) {\n  throw new Error('Not signed in: run LinkedIn login before scraping');\n}","typeGuard":"function isSignedIn(cookies) {\n  return Array.isArray(cookies) && cookies.some((c) => c.name === 'JSESSIONID' && !!c.value);\n}","tryCatchPattern":"try {\n  const rows = await fetchInboxRows(page);\n} catch (e) {\n  if (String(e.message).includes('JSESSIONID')) {\n    await interactiveLogin(page); // or restore saved cookies\n    return fetchInboxRows(page);\n  }\n  throw e;\n}","preventionTips":["Persist LinkedIn cookies/storageState between runs","Run an explicit login step before scraping commands","Detect expired sessions early with a lightweight auth check","Avoid ephemeral incognito contexts without loaded cookies"],"tags":["linkedin","authentication","csrf","session-expired"],"backgroundTag":"missing-auth-session","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}