{"record":{"id":"ee04fa3b21eeafb1","repo":"jackwener/OpenCLI","slug":"browser-session-required-for-xiaohongshu-follow","errorCode":null,"errorMessage":"Browser session required for xiaohongshu follow","messagePattern":"Browser session required for xiaohongshu follow","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/follow.js","lineNumber":170,"sourceCode":"    name: 'follow',\n    access: 'write',\n    description: '关注小红书用户 (profile UI automation)',\n    domain: 'www.xiaohongshu.com',\n    strategy: Strategy.COOKIE,\n    navigateBefore: false,\n    browser: true,\n    args: [\n        {\n            name: 'user-id',\n            required: true,\n            positional: true,\n            help: 'User ID (e.g. 5d8f88dc0000000001005d3a) or profile URL',\n        },\n    ],\n    columns: ['status', 'user_id', 'url'],\n    func: async (page, kwargs) => {\n        if (!page) {\n            throw new CommandExecutionError('Browser session required for xiaohongshu follow');\n        }\n        try {\n            const userId = assertUserId(kwargs['user-id']);\n            const url = `https://www.xiaohongshu.com/user/profile/${userId}`;\n            await page.goto(url);\n            await page.wait({ time: PROFILE_SETTLE_MS / 1000 });\n\n            const hrefRaw = unwrapEvaluateResult(await page.evaluate('() => location.href'));\n            if (typeof hrefRaw !== 'string') {\n                throw new CommandExecutionError('xiaohongshu/follow: malformed current-url payload');\n            }\n            const parsedHref = new URL(hrefRaw);\n            if (parsedHref.protocol !== 'https:' || !isXiaohongshuHost(parsedHref.hostname)) {\n                throw new CommandExecutionError(\n                    `xiaohongshu/follow: expected Xiaohongshu profile host, got ${parsedHref.hostname}`,\n                );\n            }\n            if (/\\/login(?:[/?#]|$)/i.test(parsedHref.pathname)) {","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/follow.js#L152-L188","documentation":"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'.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Start the opencli browser daemon / connect the extension, then re-run the follow command.","Verify with a read-only xiaohongshu command (e.g. feed) that the browser session is live before following.","Check OPENCLI browser connection settings (profile, port) if the daemon is running but page is still null."],"exampleFix":"// before\nopencli xiaohongshu follow --user-id 5d8f88dc0000000001005d3a\n// after\nopencli browser connect   # or start the daemon / open Chrome with the extension\nopencli xiaohongshu follow --user-id 5d8f88dc0000000001005d3a","handlingStrategy":"validation","validationCode":"// before invoking follow, ensure a browser session exists\nconst connected = await opencli.browser.isConnected();\nif (!connected) await opencli.browser.connect();\n// or in shell: opencli browser connect && opencli xiaohongshu follow ...","typeGuard":null,"tryCatchPattern":"try {\n  await runFollowCommand();\n} catch (err) {\n  if (err.code === 'COMMAND_EXEC' && err.message.includes('Browser session required')) {\n    await connectBrowserSession();\n    return runFollowCommand();\n  }\n  throw err;\n}","preventionTips":["Always connect the browser daemon/extension before browser commands","Run a read-only command first to verify the session is live","Health-check the session in scripts before batch follow operations"],"tags":["browser-session","missing-dependency","browser-automation","xiaohongshu"],"backgroundTag":"browser-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}