jackwener/OpenCLI · error · CommandExecutionError

Browser page required

Error message

Browser page required

What it means

requirePage is the guard used by all boss commands to assert that a browser page object was provided. If page is null/undefined the command cannot drive a browser, so it throws this CommandExecutionError immediately.

Source

Thrown at clis/boss/utils.js:18

import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';

// ── Constants ───────────────────────────────────────────────────────────────
const BOSS_DOMAIN = 'www.zhipin.com';
const CHAT_URL = `https://${BOSS_DOMAIN}/web/chat/index`;
const COOKIE_EXPIRED_CODES = new Set([7, 37]);
const COOKIE_EXPIRED_MSG = 'Cookie 已过期!请在当前 Chrome 浏览器中重新登录 BOSS 直聘。';
const AMBIGUOUS_AUTH_CODE = 37;
const ENVIRONMENT_REJECTED_MARKERS = ['环境存在异常', '环境异常', 'abnormal environment'];
const RECRUITER_ONLY_MSG = '该命令仅支持招聘端(BOSS 端)账号,请使用招聘者账号登录后重试。';
const DEFAULT_TIMEOUT = 15_000;
// ── Core helpers ────────────────────────────────────────────────────────────
/**
 * Assert that page is available (non-null).
 */
export function requirePage(page) {
    if (!page)
        throw new CommandExecutionError('Browser page required');
}
export function readPositiveInteger(raw, name, fallback, max) {
    const value = raw === undefined || raw === null || raw === '' ? fallback : Number(raw);
    if (!Number.isInteger(value) || value < 1) {
        throw new ArgumentError(`boss ${name} must be a positive integer`);
    }
    if (max !== undefined && value > max) {
        throw new ArgumentError(`boss ${name} must be <= ${max}`);
    }
    return value;
}
export function readRequiredString(raw, name) {
    const value = String(raw ?? '').trim();
    if (!value) {
        throw new ArgumentError(`boss ${name} cannot be empty`);
    }
    return value;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Launch or connect a browser session before running the command (opencli's browser open/connect flow)
  2. Check that the previous browser process did not crash — restart it if needed
  3. When calling func directly, always pass the wrapped page object
  4. Add a session health check before batch runs so a dead browser fails fast
  5. Catch CommandExecutionError and prompt the user to start a browser session

Example fix

// before
await cli('boss', 'search', { query: 'java' }); // no browser attached
// after
await opencli.browser.open();          // ensure a session exists
const page = await opencli.browser.getPage();
if (!page) throw new Error('start a browser session first');
await cli('boss', 'search', { query: 'java' });
Defensive patterns

Strategy: validation

Validate before calling

if (!page) throw new Error('open a browser session before running boss commands');

Type guard

function hasPage(s) { return Boolean(s && typeof s.evaluate === 'function'); }

Try / catch

try {
  return await cli('boss', cmd, opts);
} catch (e) {
  if (String(e.message).includes('Browser page required')) {
    await openBrowserSession();
    return cli('boss', cmd, opts);
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking a boss command without an active browser session (opencli running without a browser connection), or programmatically calling the underlying func with page omitted/null.

Common situations: Running the CLI in an environment where no browser was launched/attached; browser crashed and the session returned null; forgetting to open/connect a browser before running boss commands; test harnesses passing no page.

Related errors


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