jackwener/OpenCLI · error · CommandExecutionError

Browser session required for xiaohongshu unfollow

Error message

Browser session required for xiaohongshu unfollow

What it means

The xiaohongshu/unfollow command is a browser-automation command (browser: true) that drives a Chrome page to click the unfollow button. The cli func receives `page` from the runtime; when there is no browser session (page is null/undefined), this CommandExecutionError is thrown before any work happens. It signals that the command cannot run headless-of-browser.

Source

Thrown at clis/xiaohongshu/unfollow.js:201

    name: 'unfollow',
    access: 'write',
    description: '取消关注小红书用户 (profile UI automation)',
    domain: 'www.xiaohongshu.com',
    strategy: Strategy.COOKIE,
    navigateBefore: false,
    browser: true,
    args: [
        {
            name: 'user-id',
            required: true,
            positional: true,
            help: 'User ID (e.g. 5d8f88dc0000000001005d3a) or profile URL',
        },
    ],
    columns: ['status', 'user_id', 'url'],
    func: async (page, kwargs) => {
        if (!page) {
            throw new CommandExecutionError('Browser session required for xiaohongshu unfollow');
        }
        try {
            const userId = assertUserId(kwargs['user-id']);
            const url = `https://www.xiaohongshu.com/user/profile/${userId}`;
            await page.goto(url);
            await page.wait({ time: PROFILE_SETTLE_MS / 1000 });

            const hrefRaw = unwrapEvaluateResult(await page.evaluate('() => location.href'));
            if (typeof hrefRaw !== 'string') {
                throw new CommandExecutionError('xiaohongshu/unfollow: malformed current-url payload');
            }
            const parsedHref = new URL(hrefRaw);
            if (parsedHref.protocol !== 'https:' || !isXiaohongshuHost(parsedHref.hostname)) {
                throw new CommandExecutionError(
                    `xiaohongshu/unfollow: expected Xiaohongshu profile host, got ${parsedHref.hostname}`,
                );
            }
            if (/\/login(?:[/?#]|$)/i.test(parsedHref.pathname)) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Start/ensure the browser session before running the command (launch Chrome and log into www.xiaohongshu.com as the library requires)
  2. Re-run the command so the CLI runtime can attach a fresh page; if the previous session crashed, restart it
  3. If calling func programmatically, pass a real page object from your browser/session helper instead of null
  4. Verify Chrome is installed and reachable in your environment (CI: use a Chrome-capable image)

Example fix

// before
await unfollowFunc(null, { 'user-id': id });  // page is null
// after
const page = await session.openPage('www.xiaohongshu.com');
await unfollowFunc(page, { 'user-id': id });
Defensive patterns

Strategy: validation

Validate before calling

if (!page) throw new Error('Open a browser session before calling xiaohongshu unfollow');

Type guard

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

Try / catch

try { await cli.unfollow({ 'user-id': id }); } catch (e) { if (String(e.message).includes('Browser session required')) { await session.start(); /* then retry */ } else throw e; }

Prevention

When it happens

Trigger: Invoking the command without a connected/started browser session; running in an environment where Chrome is not available or the session failed to launch; calling the underlying func directly (e.g. in tests or programmatic use) with page=null; the browser process crashed or was closed before the command ran.

Common situations: Forgetting to start the browser/login flow before running site commands; CI containers without Chrome; stale session after Chrome was manually closed; a wrapper library that passes null page when Strategy.COOKIE session setup fails silently.

Related errors


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