jackwener/OpenCLI · error · CommandExecutionError

Browser session required for linkedin-learning trending

Error message

Browser session required for linkedin-learning trending

What it means

Thrown at the start of the trending command when the func is invoked without a live browser page. The trending command is declared with browser:true; the CLI passes the page handle only when a browser session is running, so a null page means the command was invoked outside a browser-enabled session.

Source

Thrown at clis/linkedin-learning/trending.js:40

        viewers: card?.viewerCount ?? '',
        url: slug ? `https://www.linkedin.com/learning/${slug}` : '',
    };
}

cli({
    site: 'linkedin-learning',
    name: 'trending',
    access: 'read',
    description: 'Browse LinkedIn Learning recommended courses across personalized carousels',
    domain: DOMAIN,
    strategy: Strategy.COOKIE,
    browser: true,
    args: [
        { name: 'limit', type: 'int', default: 10, help: `Maximum results to return (1-${MAX_LIMIT})` },
    ],
    columns: ['rank', 'group', 'type', 'title', 'difficulty', 'viewers', 'url'],
    func: async (page, args) => {
        if (!page) throw new CommandExecutionError('Browser session required for linkedin-learning trending');
        const limit = parseLimit(args.limit);

        const url = `https://www.linkedin.com/learning-api/feedRecommendationGroups?countPerCarousel=${MAX_PER_CAROUSEL}&q=learner`;
        const result = await fetchLinkedInLearningApi(page, url);
        if (!result?.json) {
            throw new CommandExecutionError(`LinkedIn Learning feedRecommendationGroups failed: ${result?.error ?? 'no payload'}`);
        }
        const groups = result.json?.elements;
        if (!Array.isArray(groups)) {
            throw new CommandExecutionError('LinkedIn Learning feedRecommendationGroups returned malformed payload: missing elements array');
        }
        const rows = [];
        const seen = new Set();
        let rank = 1;
        let sawCards = false;
        for (const group of groups) {
            const carousels = Array.isArray(group?.carousels) ? group.carousels : [];
            for (const carousel of carousels) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Run the command through the CLI normally so a browser session is started (browser:true commands must run in a browser-enabled invocation).
  2. Start the shared browser session (per CLI docs, e.g. a browser open/login command) before trending.
  3. Check that browser launch is not failing (missing Chrome/Playwright deps) causing page to be null.
  4. In tests, pass a stub page object rather than null.

Example fix

// before
clio linkedin-learning trending          # no browser session -> error
// after
clio browser open
clio linkedin-learning trending
Defensive patterns

Strategy: validation

Validate before calling

// guard before invoking browser-required commands
if (!page || typeof page.goto !== 'function') {
  throw new Error('Browser session required: run via a browser-enabled CLI session');
}

Type guard

function hasLivePage(page) {
  return !!page && typeof page.goto === 'function' && typeof page.evaluate === 'function';
}

Try / catch

try {
  const rows = await trending(page);
} catch (e) {
  if (e.message.includes('Browser session required')) {
    page = await ensureBrowserSession(); // start/reuse the CLI's browser
    return trending(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running 'clio linkedin-learning trending' without an active browser session (the CLI did not launch/attach the shared browser), or calling the command's func programmatically with page=null.

Common situations: Forgetting to start/reuse the CLI's browser session before browser-only commands, running in an environment where browser launch failed silently, or unit tests invoking func directly with no page.

Related errors


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