jackwener/OpenCLI · error · CommandExecutionError

Browser session required

Error message

Browser session required

What it means

Thrown by ensurePage when the browser page reference is null/undefined — i.e. no active browser session page exists to run the Instagram metadata fetch in. Callers must establish a browser page before invoking Instagram metadata operations.

Source

Thrown at clis/instagram/download.js:298

        const picked = pickNode(nodes[index], index);
        if (!picked.ok) {
          return { ok: false, errorCode: 'COMMAND_EXEC', error: picked.error };
        }
        items.push(picked.item);
      }

      return {
        ok: true,
        shortcode: media.code,
        owner: media?.user?.username || '',
        items,
      };
    })()
  `;
}
function ensurePage(page) {
    if (!page)
        throw new CommandExecutionError('Browser session required');
    return page;
}
function normalizeFetchResult(result) {
    const unwrapped = unwrapEvaluateResult(result);
    if (!unwrapped || typeof unwrapped !== 'object' || Array.isArray(unwrapped)) {
        throw new CommandExecutionError('Failed to fetch Instagram media metadata');
    }
    if (typeof unwrapped.ok !== 'boolean') {
        throw new CommandExecutionError('Instagram media metadata returned malformed result');
    }
    return unwrapped;
}
function handleFetchFailure(result) {
    const message = result.error || 'Instagram media fetch failed';
    if (result.errorCode === 'AUTH_REQUIRED') {
        throw new AuthRequiredError('instagram.com', message);
    }
    if (result.errorCode === 'RATE_LIMITED') {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Ensure the browser session is started and a page is created before downloading
  2. Check browser launch errors earlier in the flow (missing browser, bad profile path)
  3. Re-run the command so a fresh page is established

Example fix

// before
const page = maybeGetPage(); // undefined
await download(page);
// after
const page = await launchBrowserAndGetPage();
if (!page) throw ...; // or ensure the flow guarantees a page
await download(page);
Defensive patterns

Strategy: try-catch

Validate before calling

const page = await browser.newPage();
if (!page) throw new Error('Browser page could not be created before download');

Type guard

function hasPage(p) {
  return !!p && typeof p.evaluate === 'function';
}

Try / catch

try {
  await igDownload(url);
} catch (e) {
  if (e.message === 'Browser session required') {
    console.error('Initialize/relaunch the browser session before downloading.');
  } else throw e;
}

Prevention

When it happens

Trigger: Calling browserPage-driven download flow when browser launch or page creation failed/was skipped, so page is falsy when ensurePage is called.

Common situations: Browser failed to launch (missing browser binary), session teardown ran before download, or code path invoked without initializing the browser session.

Related errors


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