{"record":{"id":"45e83b03c55b8282","repo":"jackwener/OpenCLI","slug":"linkedin-cookie-lookup-failed-error-message-45e83b","errorCode":null,"errorMessage":"LinkedIn cookie lookup failed: ${error?.message || error}","messagePattern":"LinkedIn cookie lookup failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/shared.js","lineNumber":125,"sourceCode":"  if (!value) throw new ArgumentError(`${label} is required`);\n  return value;\n}\n\nexport function parseLimit(value, fallback, max) {\n  if (value === undefined || value === null || value === '') return fallback;\n  const parsed = Number(value);\n  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');","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/shared.js#L107-L143","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the browser session is launched and the page is open before calling csrf.","Check the embedded cause message (`error?.message || error`) for the driver-level problem and fix that first.","Restart the browser/session and rerun the command.","Pin compatible versions of the automation driver/browser; update the CLI if getCookies signature changed."],"exampleFix":"// before\nconst page = await browser.newPage();\nawait page.close();\nawait csrf({ page }); // getCookies on closed context\n// after\nconst page = await browser.newPage();\nawait csrf({ page }); // keep page open until after cookie lookup","handlingStrategy":"try-catch","validationCode":"// Verify the page is live before cookie lookup\nif (!page || page.isClosed?.()) throw new Error('Browser page is closed; relaunch before csrf lookup');","typeGuard":"function isUsablePage(p) {\n  return !!p && typeof p.getCookies === 'function' && !(typeof p.isClosed === 'function' && p.isClosed());\n}","tryCatchPattern":"let jsession;\ntry {\n  jsession = await requireLinkedInCookie(page, 'csrf');\n} catch (e) {\n  if (e instanceof CommandExecutionError && e.message.startsWith('LinkedIn cookie lookup failed')) {\n    console.error('Driver error during getCookies; relaunching browser...', e.message);\n    page = await relaunchBrowser();\n  } else throw e;\n}","preventionTips":["Keep the browser/page open for the whole command lifetime.","Pin matching versions of the CLI, automation library, and browser binary.","Check page.isClosed() before cookie-dependent calls.","Capture the embedded cause message; it names the real driver failure."],"tags":["browser-automation","cookie-lookup","driver-error","linkedin"],"backgroundTag":"browser-session-unavailable","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}