{"record":{"id":"4123bba55fe54247","repo":"jackwener/OpenCLI","slug":"xianyu-messages-requires-a-logged-in-browser-sessi","errorCode":null,"errorMessage":"Xianyu messages requires a logged-in browser session","messagePattern":"Xianyu messages requires a logged-in browser session","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/messages.js","lineNumber":65,"sourceCode":"        const userId = hasIds ? normalizeNumericId(kwargs.user_id, 'user_id', '3650092411') : '';\n        const limit = normalizeLimit(kwargs.limit, DEFAULT_MESSAGE_LIMIT, MAX_MESSAGE_LIMIT, 'messages --limit');\n        let url = '';\n        if (hasIds) {\n            url = buildChatUrl(itemId, userId);\n            await page.goto(url);\n        } else {\n            if (!page.getCurrentUrl || !/https:\\/\\/www\\.goofish\\.com\\/im\\b/.test(await page.getCurrentUrl())) {\n                await page.goto('https://www.goofish.com/im');\n            }\n        }\n        await page.wait(2);\n        if (rank > 0) {\n            requireClickResult(await page.evaluate(buildClickInboxConversationEvaluate(rank - 1)), 'messages rank click');\n            await page.wait(2);\n        }\n        const state = requireEvaluateObject(await page.evaluate(buildExtractChatStateEvaluate(limit)), 'messages');\n        if (state?.requiresAuth) {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu messages requires a logged-in browser session');\n        }\n        if (!Array.isArray(state.messages)) {\n            throw new CommandExecutionError('Xianyu messages returned malformed message list');\n        }\n        const messages = state.messages;\n        if (!messages.length) {\n            throw new EmptyResultError('xianyu messages', 'No visible messages were found in this Xianyu conversation');\n        }\n        return messages.slice(-limit).map((message, index) => ({\n            index: index + 1,\n            peer_name: state.peer_name || '',\n            item_title: state.item_title || '',\n            message: message.text || '',\n            item_id: itemId,\n            peer_user_id: userId,\n            url: url || '',\n        }));\n    },","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/messages.js#L47-L83","documentation":"The chat-state extraction script executed inside the Goofish page reports requiresAuth when the page is not logged in (login wall / redirect detected). The CLI translates this into AuthRequiredError('www.goofish.com', ...) at clis/xianyu/messages.js:65, telling the operator the automation browser needs an authenticated www.goofish.com session before messages can be read.","triggerScenarios":"Running `xianyu messages` (any targeting mode) while the automation browser's goofish.com session is logged out, expired, or blocked — the in-page extraction returns { requiresAuth: true }.","commonSituations":"Fresh browser profile with no login; session cookie expired since the last run; Goofish risk-control forcing re-login; headless profile invalidated after a browser update; running from a server without completing the interactive login step.","solutions":["Open www.goofish.com in the automation browser and log in manually (scan QR / enter credentials), then re-run the command.","Persist the browser profile/cookies so the login survives restarts.","If the profile was valid, re-login — session cookies on Goofish expire periodically.","Avoid headless/automation flags that trigger bot detection and forced logout; keep the profile warm with occasional authenticated visits.","Catch AuthRequiredError in wrappers and pause the pipeline until an operator re-authenticates."],"exampleFix":"// before: fails with AuthRequiredError on a cold profile\nawait cli.run(['xianyu', 'messages', '--rank', '1']);\n\n// after: check auth first and prompt for login\nif (!(await isLoggedIn('www.goofish.com'))) {\n  await openForManualLogin('https://www.goofish.com');\n}\nawait cli.run(['xianyu', 'messages', '--rank', '1']);","handlingStrategy":"try-catch","validationCode":"const cookies = await getCookies('www.goofish.com');\nif (!cookies?.some(c => c.name === 'unb' || /session|login/i.test(c.name))) await openForManualLogin('https://www.goofish.com');","typeGuard":null,"tryCatchPattern":"try {\n  await cli.run(['xianyu', 'messages', ...args]);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await promptOperatorLogin(e.domain); // e.domain === 'www.goofish.com'\n    return cli.run(['xianyu', 'messages', ...args]);\n  }\n  throw e;\n}","preventionTips":["Persist the browser profile so logins survive restarts.","Check session validity before batch runs, not per command.","Schedule periodic authenticated page visits to keep cookies warm.","Avoid aggressive headless configurations that trigger forced re-login."],"tags":["authentication","session-expired","xianyu","browser-automation"],"backgroundTag":"authentication-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}