{"record":{"id":"5cdad5483d1b252f","repo":"jackwener/OpenCLI","slug":"context-requires-an-active-signed-in-linkedin-b-5cdad5","errorCode":null,"errorMessage":"${context} requires an active signed-in LinkedIn browser session.","messagePattern":"(.+?) requires an active signed-in LinkedIn browser session\\.","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/shared.js","lineNumber":132,"sourceCode":"  if (!Number.isInteger(parsed) || parsed < 1 || parsed > max) {\n    throw new ArgumentError(`--limit must be an integer between 1 and ${max}`);\n  }\n  return parsed;\n}\n\nexport async function requireLinkedInCookie(page, context) {\n  let cookies;\n  try {\n    cookies = await page.getCookies({ url: 'https://www.linkedin.com' });\n  } catch (error) {\n    throw new CommandExecutionError(`LinkedIn cookie lookup failed: ${error?.message || error}`);\n  }\n  if (!Array.isArray(cookies)) {\n    throw new CommandExecutionError('LinkedIn cookie lookup returned malformed payload');\n  }\n  const jsession = cookies.find((c) => c.name === 'JSESSIONID')?.value;\n  if (!jsession) {\n    throw new AuthRequiredError(LINKEDIN_DOMAIN, `${context} requires an active signed-in LinkedIn browser session.`);\n  }\n  return jsession.replace(/^\"|\"$/g, '');\n}\n\nexport function buildAuthProbeScript() {\n  return String.raw`(() => {\n    const text = [\n      window.location.href || '',\n      document.title || '',\n      document.body ? (document.body.innerText || '').slice(0, 4000) : '',\n    ].join('\\n');\n    return /linkedin\\.com\\/(?:login|checkpoint|authwall|uas)/i.test(text)\n      || /\\b(sign in|log in|join linkedin|captcha|verification required)\\b/i.test(text)\n      || /(请登录|登录领英|安全验证)/.test(text);\n  })()`;\n}\n\nexport async function assertLinkedInAuthenticated(page, context) {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/shared.js#L114-L150","documentation":"requireLinkedInCookie looks for a JSESSIONID cookie scoped to https://www.linkedin.com. If no such cookie exists, it throws AuthRequiredError stating that the operation requires an active signed-in LinkedIn browser session. JSESSIONID only exists once you are logged in to LinkedIn in that browser.","triggerScenarios":"Running csrf (or any command calling requireLinkedInCookie) when the automated browser is not signed in to LinkedIn, the session expired (LinkedIn invalidates JSESSIONID), cookies were cleared, or the browser profile has never logged in.","commonSituations":"CI/headless runs with a fresh browser profile that never logged in; LinkedIn forcing re-authentication or a checkpoint (2FA/captcha); long-lived scripts after the session aged out.","solutions":["Sign in to LinkedIn in the automated browser (manually or via login flow), then rerun the command.","Use a persistent browser profile that already holds a valid session.","If the session expired, re-authenticate; complete any checkpoint verification (2FA, captcha).","Verify by visiting linkedin.com in that browser and confirming you are logged in."],"exampleFix":"// before\nconst csrfToken = await csrf({ page }); // page not signed in\n// after\nawait loginToLinkedIn(page, { email, password }); // establish JSESSIONID\nawait page.goto('https://www.linkedin.com/feed/');\nconst csrfToken = await csrf({ page });","handlingStrategy":"validation","validationCode":"const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });\nconst signedIn = Array.isArray(cookies) && cookies.some((c) => c.name === 'JSESSIONID' && c.value);\nif (!signedIn) throw new Error('Not signed in to LinkedIn; authenticate this browser first');","typeGuard":"function hasLinkedInSessionCookie(cookieArray) {\n  return Array.isArray(cookieArray) &&\n    cookieArray.some((c) => c.name === 'JSESSIONID' && typeof c.value === 'string' && c.value.length > 0);\n}","tryCatchPattern":"try {\n  const jsession = await requireLinkedInCookie(page, 'csrf');\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    console.error('LinkedIn sign-in required. Log in (complete 2FA/checkpoint) in the automated browser, then retry.');\n  } else throw e;\n}","preventionTips":["Use a persistent browser profile that stays signed in to LinkedIn.","Re-authenticate when sessions expire; expect periodic checkpoint challenges.","Confirm login state by loading linkedin.com and checking for the feed before commands.","Avoid cookie-cleared headless environments; seed the profile with a valid session."],"tags":["authentication","linkedin","session-expired","cookie","jsessionid"],"backgroundTag":"linkedin-session-not-authenticated","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}