jackwener/OpenCLI · error · CommandExecutionError

Browser session required for linkedin salesnav-search

Error message

Browser session required for linkedin salesnav-search

What it means

Thrown at the top of the salesnav-search command function (clis/linkedin/salesnav-search.js:137) when the command is invoked without a live browser page. The command is registered with browser:true, so the registry is expected to inject an authenticated page; a falsy page means the automation runtime could not or did not provide one. The library deliberately fails fast instead of attempting API calls that require a real session.

Source

Thrown at clis/linkedin/salesnav-search.js:137

  }
  return result.json;
}

cli({
  site: 'linkedin',
  name: 'salesnav-search',
  access: 'read',
  description: 'Search LinkedIn Sales Navigator for people leads by keyword',
  domain: LINKEDIN_DOMAIN,
  strategy: Strategy.UI,
  browser: true,
  args: [
    { name: 'keywords', type: 'string', required: true, positional: true, help: 'People search keywords, e.g. "quality manager food manufacturing"' },
    { name: 'limit', type: 'number', default: 25, help: 'Maximum leads to return (1-500, fetched 25 per request)' },
  ],
  columns: ['rank', 'name', 'title', 'company', 'location', 'degree', 'profile_url', 'lead_url', 'recipient_urn'],
  func: async (page, args) => {
    if (!page) throw new CommandExecutionError('Browser session required for linkedin salesnav-search');
    const keywords = requireStringArg(args, 'keywords', '--keywords');
    const limit = parseLimit(args.limit);

    await page.goto(SALES_HOME);
    await page.wait(6);

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

    const leads = [];
    const seen = new Set();
    for (let start = 0; leads.length < limit && start < 2000; start += PAGE_SIZE) {
      const result = unwrapEvaluateResult(await page.evaluate(fetchLeadSearchScript(leadSearchUrl(keywords, start), csrf)));
      const json = requireLeadSearchResult(result);

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the command through the opencli CLI runner so it creates the browser session required by Strategy.UI/browser:true instead of calling func directly.
  2. Ensure the browser backend is installed and can launch (check playwright/chromium availability and DISPLAY settings in headless CI).
  3. If calling programmatically, establish a session first and pass a valid, logged-in LinkedIn page as the first argument.
  4. Check the registry/daemon logs to confirm the command was resolved with its browser:true metadata intact (a custom registry wrapper may drop it).

Example fix

// before (direct call, no page)
await salesNavSearchFunc(null, { keywords: 'quality manager' });
// after (open a session first)
const page = await openBrowserSession({ site: 'linkedin', domain: 'www.linkedin.com' });
await salesNavSearchFunc(page, { keywords: 'quality manager' });
Defensive patterns

Strategy: validation

Validate before calling

// Check runtime prerequisites before invoking the command:
if (!page || typeof page.evaluate !== 'function') {
  throw new Error('salesnav-search requires a live browser page; run via the opencli runner with browser support');
}

Type guard

function hasBrowserPage(p) {
  return Boolean(p) && typeof p.goto === 'function' && typeof p.evaluate === 'function';
}

Try / catch

try {
  await run('linkedin salesnav-search', [keywords]);
} catch (err) {
  if (/Browser session required/.test(err.message)) {
    console.error('Launch the opencli browser session first (check chromium install / headless setup).');
    process.exitCode = 2;
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling the salesnav-search func directly (or via __test__ exports) with page=null/undefined; running through a runner that ignores the command's browser:true flag; the browser daemon failing to launch so the registry passes a null page to func.

Common situations: Invoking commands programmatically in scripts or tests without spinning up the browser session; headless CI environments where Chromium/playwright cannot start; misconfigured opencli runner that skips Strategy.UI session creation.

Related errors


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