jackwener/OpenCLI · error · CommandExecutionError

Browser page required

Error message

Browser page required

What it means

Same guard as the daily command: the v2ex me command declares browser:true under Strategy.COOKIE and throws CommandExecutionError('Browser page required') when its func is invoked with a falsy page. It prevents a crash on page.goto when the browser layer did not supply a page.

Source

Thrown at clis/v2ex/me.js:18

/**
 * V2EX Me (Profile/Balance) adapter.
 */
import { CommandExecutionError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
cli({
    site: 'v2ex',
    name: 'me',
    access: 'read',
    description: 'V2EX 获取个人资料 (余额/未读提醒)',
    domain: 'www.v2ex.com',
    strategy: Strategy.COOKIE,
    browser: true,
    args: [],
    columns: ['username', 'balance', 'unread_notifications', 'daily_reward_ready'],
    func: async (page) => {
        if (!page)
            throw new CommandExecutionError('Browser page required');
        if (process.env.OPENCLI_VERBOSE) {
            console.error('[opencli:v2ex] Navigating to /');
        }
        await page.goto('https://www.v2ex.com/');
        // Cloudflare challenge bypass wait
        for (let i = 0; i < 5; i++) {
            await new Promise(r => setTimeout(r, 1500));
            const title = await page.evaluate(`() => document.title`);
            if (!title?.includes('Just a moment'))
                break;
            if (process.env.OPENCLI_VERBOSE)
                console.error('[opencli:v2ex] Waiting for Cloudflare...');
        }
        // Evaluate DOM to extract user profile
        const data = await page.evaluate(`
      async () => {
        let username = 'Unknown';
        const navLinks = Array.from(document.querySelectorAll('a.top')).map(a => a.textContent?.trim());

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Install the browser runtime and system deps (e.g. playwright install chromium / install-deps).
  2. Invoke the command through the CLI so the registry launches the browser and passes a page.
  3. Check prior log lines for the underlying browser launch failure and resolve it (profile lock, missing executable).
  4. Retry in a normal desktop environment to rule out sandbox/display issues in headless mode.

Example fix

// before
await meFunc(undefined); // CommandExecutionError: Browser page required
// after: run via registry
// $ opencli v2ex me
Defensive patterns

Strategy: validation

Validate before calling

if (!page || typeof page.goto !== 'function') {
  throw new Error('Browser page unavailable — verify browser runtime is installed and invoke via the CLI');
}

Type guard

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

Try / catch

try {
  await runMeCommand();
} catch (e) {
  if (e.message === 'Browser page required') {
    // provision/repair browser environment, then retry
  } else throw e;
}

Prevention

When it happens

Trigger: Invoking the v2ex me command when browser provisioning failed or was skipped — browser binary missing, launch error, or calling the registered func directly without a page argument.

Common situations: Headless CI container without Chromium; playwright browsers not installed; browser user-data-dir locked by another process; programmatic misuse calling func(undefined).

Related errors


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