jackwener/OpenCLI · error · AuthRequiredError
${context} requires an active signed-in LinkedIn browser ses
Error message
${context} requires an active signed-in LinkedIn browser session. What it means
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.
Source
Thrown at clis/linkedin/shared.js:132
if (!Number.isInteger(parsed) || parsed < 1 || parsed > max) {
throw new ArgumentError(`--limit must be an integer between 1 and ${max}`);
}
return parsed;
}
export async function requireLinkedInCookie(page, context) {
let cookies;
try {
cookies = await page.getCookies({ url: 'https://www.linkedin.com' });
} catch (error) {
throw new CommandExecutionError(`LinkedIn cookie lookup failed: ${error?.message || error}`);
}
if (!Array.isArray(cookies)) {
throw new CommandExecutionError('LinkedIn cookie lookup returned malformed payload');
}
const jsession = cookies.find((c) => c.name === 'JSESSIONID')?.value;
if (!jsession) {
throw new AuthRequiredError(LINKEDIN_DOMAIN, `${context} requires an active signed-in LinkedIn browser session.`);
}
return jsession.replace(/^"|"$/g, '');
}
export function buildAuthProbeScript() {
return String.raw`(() => {
const text = [
window.location.href || '',
document.title || '',
document.body ? (document.body.innerText || '').slice(0, 4000) : '',
].join('\n');
return /linkedin\.com\/(?:login|checkpoint|authwall|uas)/i.test(text)
|| /\b(sign in|log in|join linkedin|captcha|verification required)\b/i.test(text)
|| /(请登录|登录领英|安全验证)/.test(text);
})()`;
}
export async function assertLinkedInAuthenticated(page, context) {View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before
const csrfToken = await csrf({ page }); // page not signed in
// after
await loginToLinkedIn(page, { email, password }); // establish JSESSIONID
await page.goto('https://www.linkedin.com/feed/');
const csrfToken = await csrf({ page }); Defensive patterns
Strategy: validation
Validate before calling
const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });
const signedIn = Array.isArray(cookies) && cookies.some((c) => c.name === 'JSESSIONID' && c.value);
if (!signedIn) throw new Error('Not signed in to LinkedIn; authenticate this browser first'); Type guard
function hasLinkedInSessionCookie(cookieArray) {
return Array.isArray(cookieArray) &&
cookieArray.some((c) => c.name === 'JSESSIONID' && typeof c.value === 'string' && c.value.length > 0);
} Try / catch
try {
const jsession = await requireLinkedInCookie(page, 'csrf');
} catch (e) {
if (e instanceof AuthRequiredError) {
console.error('LinkedIn sign-in required. Log in (complete 2FA/checkpoint) in the automated browser, then retry.');
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- LinkedIn JSESSIONID cookie not found. Please sign in to Link
- Bilibili creator-center login is required: ${message}
- LinkedIn JSESSIONID cookie not found. Please sign in to Link
- LinkedIn JSESSIONID cookie not found. Please sign in to Link
- ${context} requires an active signed-in LinkedIn browser ses
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5cdad5483d1b252f.
Report an issue: GitHub.