jackwener/OpenCLI · error · AuthRequiredError

Xianyu chat requires a logged-in browser session

Error message

Xianyu chat requires a logged-in browser session

What it means

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.

Solutions

  1. Log in to www.goofish.com in the same browser session, then retry the chat command
  2. Restore a valid cookie/user-data-dir profile before running chat commands
  3. Add a quick auth check (e.g. hasXianyuIdentityCookie) before invoking chat
  4. Catch AuthRequiredError and route the user to the login flow

Example fix

// before
await sendXianyuChat({ itemId, userId, text });
// after
if (!(await hasXianyuIdentityCookie(page))) {
  await loginXianyu(page);
}
await sendXianyuChat({ itemId, userId, text });
Defensive patterns

Strategy: try-catch

Validate before calling

if (!(await hasXianyuIdentityCookie(page))) {
  await loginXianyu(page);
}

Type guard

function isAuthRequiredError(e) {
  return e instanceof AuthRequiredError || e?.name === 'AuthRequiredError';
}

Try / catch

try {
  await sendXianyuChat(kwargs);
} catch (e) {
  if (isAuthRequiredError(e)) {
    await loginXianyu(page);
    return sendXianyuChat(kwargs);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling the xianyu chat send command when the browser session is anonymous; buildExtractChatStateEvaluate detects a login wall on the chat URL.

Common situations: Session cookies expired between login and chat use; fresh browser profile never logged in; goofish logged the session out due to risk control.

Related errors


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

Appendix: source

Thrown at clis/xianyu/chat.js:30

    strategy: Strategy.COOKIE,
    navigateBefore: false,
    browser: true,
    args: [
        { name: 'item_id', required: true, positional: true, help: '闲鱼商品 item_id' },
        { name: 'user_id', required: true, positional: true, help: '聊一聊对方的 user_id / peerUserId' },
        { name: 'text', help: 'Message to send after opening the chat' },
    ],
    columns: ['status', 'peer_name', 'item_title', 'price', 'location', 'message'],
    func: async (page, kwargs) => {
        const itemId = normalizeNumericId(kwargs.item_id, 'item_id', '1038951278192');
        const userId = normalizeNumericId(kwargs.user_id, 'user_id', '3650092411');
        const url = buildChatUrl(itemId, userId);
        const text = String(kwargs.text || '').trim();
        await page.goto(url);
        await page.wait(2);
        const state = requireEvaluateObject(await page.evaluate(buildExtractChatStateEvaluate()), 'chat');
        if (state?.requiresAuth) {
            throw new AuthRequiredError('www.goofish.com', 'Xianyu chat requires a logged-in browser session');
        }
        if (!state?.can_input) {
            throw selectorError('闲鱼聊天输入框', '未找到可用的聊天输入框,请确认该会话页已正确加载');
        }
        if (!text) {
            return [{
                status: 'ready',
                peer_name: state.peer_name || '',
                item_title: state.item_title || '',
                price: state.price || '',
                location: state.location || '',
                message: (state.visible_messages || []).slice(-1)[0] || '',
                peer_user_id: userId,
                item_id: itemId,
                url,
                item_url: state.item_url || '',
            }];
        }

View on GitHub (pinned to 49907e53dc)