jackwener/OpenCLI · error · CommandExecutionError

Browser session required for xiaohongshu follow

Error message

Browser session required for xiaohongshu follow

What it means

The follow command is a browser-automation command; without a connected browser session there is no `page` to navigate. The library throws CommandExecutionError (exit 1) when func is invoked with page == null rather than silently failing later. Effectively: 'start/connect a browser session first'.

Source

Thrown at clis/xiaohongshu/follow.js:170

    name: 'follow',
    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 follow');
        }
        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/follow: malformed current-url payload');
            }
            const parsedHref = new URL(hrefRaw);
            if (parsedHref.protocol !== 'https:' || !isXiaohongshuHost(parsedHref.hostname)) {
                throw new CommandExecutionError(
                    `xiaohongshu/follow: expected Xiaohongshu profile host, got ${parsedHref.hostname}`,
                );
            }
            if (/\/login(?:[/?#]|$)/i.test(parsedHref.pathname)) {

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Start the opencli browser daemon / connect the extension, then re-run the follow command.
  2. Verify with a read-only xiaohongshu command (e.g. feed) that the browser session is live before following.
  3. Check OPENCLI browser connection settings (profile, port) if the daemon is running but page is still null.

Example fix

// before
opencli xiaohongshu follow --user-id 5d8f88dc0000000001005d3a
// after
opencli browser connect   # or start the daemon / open Chrome with the extension
opencli xiaohongshu follow --user-id 5d8f88dc0000000001005d3a
Defensive patterns

Strategy: validation

Validate before calling

// before invoking follow, ensure a browser session exists
const connected = await opencli.browser.isConnected();
if (!connected) await opencli.browser.connect();
// or in shell: opencli browser connect && opencli xiaohongshu follow ...

Try / catch

try {
  await runFollowCommand();
} catch (err) {
  if (err.code === 'COMMAND_EXEC' && err.message.includes('Browser session required')) {
    await connectBrowserSession();
    return runFollowCommand();
  }
  throw err;
}

Prevention

When it happens

Trigger: Running the follow command with no browser daemon running, the extension not connected, or invoking the CLI in a mode (e.g. dry listing/help piping) where no page handle is passed.

Common situations: Forgot to launch/connect the Chrome extension bridge; daemon died between commands; running inside CI without a browser profile configured; invoking the command programmatically without a page.

Related errors


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