{"record":{"id":"1bebed5079e7ed04","repo":"jackwener/OpenCLI","slug":"xianyu-chat-requires-a-logged-in-browser-session","errorCode":null,"errorMessage":"Xianyu chat requires a logged-in browser session","messagePattern":"Xianyu chat requires a logged-in browser session","errorType":"error_code","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/chat.js","lineNumber":30,"sourceCode":"    strategy: Strategy.COOKIE,\n    navigateBefore: false,\n    browser: true,\n    args: [\n        { name: 'item_id', required: true, positional: true, help: '闲鱼商品 item_id' },\n        { name: 'user_id', required: true, positional: true, help: '聊一聊对方的 user_id / peerUserId' },\n        { name: 'text', help: 'Message to send after opening the chat' },\n    ],\n    columns: ['status', 'peer_name', 'item_title', 'price', 'location', 'message'],\n    func: async (page, kwargs) => {\n        const itemId = normalizeNumericId(kwargs.item_id, 'item_id', '1038951278192');\n        const userId = normalizeNumericId(kwargs.user_id, 'user_id', '3650092411');\n        const url = buildChatUrl(itemId, userId);\n        const text = String(kwargs.text || '').trim();\n        await page.goto(url);\n        await page.wait(2);\n        const state = requireEvaluateObject(await page.evaluate(buildExtractChatStateEvaluate()), 'chat');\n        if (state?.requiresAuth) {\n            throw new AuthRequiredError('www.goofish.com', 'Xianyu chat requires a logged-in browser session');\n        }\n        if (!state?.can_input) {\n            throw selectorError('闲鱼聊天输入框', '未找到可用的聊天输入框，请确认该会话页已正确加载');\n        }\n        if (!text) {\n            return [{\n                status: 'ready',\n                peer_name: state.peer_name || '',\n                item_title: state.item_title || '',\n                price: state.price || '',\n                location: state.location || '',\n                message: (state.visible_messages || []).slice(-1)[0] || '',\n                peer_user_id: userId,\n                item_id: itemId,\n                url,\n                item_url: state.item_url || '',\n            }];\n        }","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/chat.js#L12-L48","documentation":"The chat page extract returned state.requiresAuth=true, meaning goofish.com served the chat without a logged-in session, so messages cannot be read or sent. The library throws AuthRequiredError to abort the chat command until the user logs in.","triggerScenarios":"Calling the xianyu chat send command when the browser session is anonymous; buildExtractChatStateEvaluate detects a login wall on the chat URL.","commonSituations":"Session cookies expired between login and chat use; fresh browser profile never logged in; goofish logged the session out due to risk control.","solutions":["Log in to www.goofish.com in the same browser session, then retry the chat command","Restore a valid cookie/user-data-dir profile before running chat commands","Add a quick auth check (e.g. hasXianyuIdentityCookie) before invoking chat","Catch AuthRequiredError and route the user to the login flow"],"exampleFix":"// before\nawait sendXianyuChat({ itemId, userId, text });\n// after\nif (!(await hasXianyuIdentityCookie(page))) {\n  await loginXianyu(page);\n}\nawait sendXianyuChat({ itemId, userId, text });","handlingStrategy":"try-catch","validationCode":"if (!(await hasXianyuIdentityCookie(page))) {\n  await loginXianyu(page);\n}","typeGuard":"function isAuthRequiredError(e) {\n  return e instanceof AuthRequiredError || e?.name === 'AuthRequiredError';\n}","tryCatchPattern":"try {\n  await sendXianyuChat(kwargs);\n} catch (e) {\n  if (isAuthRequiredError(e)) {\n    await loginXianyu(page);\n    return sendXianyuChat(kwargs);\n  }\n  throw e;\n}","preventionTips":["Run a quick auth check before chat operations","Keep the session alive with periodic /personal probes","Use one shared browser profile for login and chat commands"],"tags":["auth","xianyu","chat"],"backgroundTag":"auth-session-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}