jackwener/OpenCLI · error · AuthRequiredError

LinkedIn JSESSIONID cookie not found. Please sign in to Link

Error message

LinkedIn JSESSIONID cookie not found. Please sign in to LinkedIn in the browser.

What it means

An AuthRequiredError thrown by fetchLinkedInLearningApi when, after loading linkedin.com/learning/, no JSESSIONID cookie exists in the browser context. JSESSIONID is the session cookie the CLI uses to derive the csrf-token for the in-page API fetch, so its absence means the browser has no authenticated LinkedIn session at all.

Source

Thrown at clis/linkedin-learning/shared.js:51

        },
      });
      if (res.status === 401 || res.status === 403) return { authRequired: true, status: res.status };
      if (!res.ok) return { error: 'HTTP ' + res.status };
      return { json: await res.json() };
    } catch (e) {
      return { error: 'fetch failed: ' + ((e && e.message) || String(e)) };
    }
  })()`;
}

export async function fetchLinkedInLearningApi(page, url) {
    await page.goto('https://www.linkedin.com/learning/');
    await page.wait(3);

    const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });
    const jsession = cookies.find((c) => c.name === 'JSESSIONID')?.value;
    if (!jsession) {
        throw new AuthRequiredError(DOMAIN, 'LinkedIn JSESSIONID cookie not found. Please sign in to LinkedIn in the browser.');
    }
    const csrf = jsession.replace(/^"|"$/g, '');

    const result = unwrapEvaluateResult(await page.evaluate(buildFetchScript(url, csrf)));
    if (result?.authRequired) {
        throw new AuthRequiredError(DOMAIN, `LinkedIn Learning auth failed (HTTP ${result.status ?? ''}).`);
    }
    return result;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Open the controlled browser, sign in to LinkedIn manually, then re-run the command.
  2. Point the CLI at a persistent browser profile that already has an active LinkedIn session.
  3. Complete any LinkedIn security/2FA challenge that invalidated the session.
  4. Verify cookies exist: page.getCookies({url:'https://www.linkedin.com'}) should include JSESSIONID before calling the API.
  5. Avoid incognito/ephemeral contexts; reuse the same user-data-dir each run.

Example fix

// before
const browser = await launch({ headless: true }); // fresh, signed-out context
// after
const browser = await launch({ userDataDir: PROFILE_DIR }); // profile signed in to LinkedIn
Defensive patterns

Strategy: try-catch

Validate before calling

// verify session cookies exist before invoking any linkedin-learning command
const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });
if (!cookies.some(c => c.name === 'JSESSIONID')) {
  throw new Error('Not signed in to LinkedIn: open the browser and log in first');
}

Type guard

function hasLinkedInSession(cookies) {
  return Array.isArray(cookies) && cookies.some(c => c.name === 'JSESSIONID' && !!c.value);
}

Try / catch

try {
  const rows = await trendingOrSearch(page);
} catch (e) {
  if (/JSESSIONID cookie not found|AuthRequired/i.test(e.message)) {
    await interactiveLogin(page); // open visible browser, wait for manual sign-in
    return trendingOrSearch(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: The automated/persistent browser profile was never signed in to LinkedIn, the session fully expired and cookies were cleared, the profile directory was reset, or cookies were fetched from a URL context that excludes the session (private window, fresh context).

Common situations: Running the CLI on a new machine/container with an empty browser profile, cookie purging by browser settings or cleanup jobs, LinkedIn forcing a full re-login (password change, security challenge), or launching the browser headless with a fresh context.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/fc63b37305324549. Report an issue: GitHub.