jackwener/OpenCLI · error · CommandExecutionError

Browser session required for linkedin jobs-preferences

Error message

Browser session required for linkedin jobs-preferences

What it means

CommandExecutionError thrown at the top of the linkedin jobs-preferences func when the page argument is falsy. The command requires a logged-in browser session (browser:true, COOKIE strategy) and this guard prevents navigation attempts without one. It surfaces when the session layer failed to provide a page.

Source

Thrown at clis/linkedin/jobs-preferences.js:97

    job_alerts: Array.isArray(alerts.job_alerts) ? alerts.job_alerts.map(normalizeWhitespace).filter(Boolean).join('; ') : '',
    preferences_url: normalizeWhitespace(preferences.preferences_url),
    alerts_url: normalizeWhitespace(alerts.alerts_url),
    raw_preferences: preferenceText.slice(0, 1200),
  };
}

cli({
  site: 'linkedin',
  name: 'jobs-preferences',
  access: 'read',
  description: 'Read visible LinkedIn Jobs preferences and alert settings without changing them',
  domain: 'www.linkedin.com',
  strategy: Strategy.COOKIE,
  browser: true,
  args: [],
  columns: ['open_to_work', 'job_titles', 'locations', 'job_alerts', 'preferences_url', 'alerts_url', 'raw_preferences'],
  func: async (page) => {
    if (!page) throw new CommandExecutionError('Browser session required for linkedin jobs-preferences');
    await page.goto(PREFERENCES_URL);
    await page.wait(5);
    await assertLinkedInAuthenticated(page, 'LinkedIn jobs-preferences');
    const preferences = unwrapEvaluateResult(await page.evaluate(buildPreferencesScript()));
    await page.goto(ALERTS_URL);
    await page.wait(5);
    await assertLinkedInAuthenticated(page, 'LinkedIn jobs-preferences alerts');
    const alerts = unwrapEvaluateResult(await page.evaluate(buildAlertsScript()));
    return [normalizePreferences(preferences, alerts)];
  },
});

export const __test__ = {
  inferOpenToWork,
  normalizePreferences,
};

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the command via the normal CLI entry so the session is established first
  2. Refresh LinkedIn session cookies for www.linkedin.com
  3. Fix browser launch issues (install Chromium, check sandbox flags) if the session fails to start
  4. In tests, pass a page stub implementing goto/wait/evaluate

Example fix

// before
await cli.run('jobs-preferences'); // cookies expired, no session
// after
await cli.refreshSession({ cookies: loadCookies('linkedin') });
await cli.run('jobs-preferences');
Defensive patterns

Strategy: try-catch

Validate before calling

if (!page) {
  throw new Error('Run linkedin jobs-preferences via the CLI so a browser session is started first');
}

Type guard

function hasBrowserPage(page) {
  return typeof page === 'object' && page !== null && typeof page.goto === 'function' && typeof page.wait === 'function' && typeof page.evaluate === 'function';
}

Try / catch

try {
  const result = await runCli(['linkedin', 'jobs-preferences']);
} catch (err) {
  if (String(err.message).includes('Browser session required')) {
    await startBrowserSession({ cookies: loadLinkedInCookies() });
    // retry the command
  } else throw err;
}

Prevention

When it happens

Trigger: Running jobs-preferences without a working browser session: missing/expired LinkedIn cookies, failed browser launch, or calling func(null) directly.

Common situations: Cookie store expired so login failed silently; headless CI missing Chromium; invoking the command handler in tests without a page stub.

Related errors


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