jackwener/OpenCLI · error · AuthRequiredError

Ke no user-name DOM anchor — anonymous or SSR failed

Error message

Ke no user-name DOM anchor — anonymous or SSR failed

What it means

After confirming the `lianjia_token` cookie, verifyKeIdentity injects a DOM probe looking for the logged-in user-name anchor (.typeShowUser a, .userNick, .user-name, .myInfo a). If no anchor yields a non-empty username it throws AuthRequiredError — either the session is effectively anonymous or the server-rendered header failed to render, so identity cannot be confirmed.

Source

Thrown at clis/ke/auth.js:31

  await page.goto('https://www.ke.com/');
  await page.wait(2);
  const probe = await page.evaluate(`
    (() => {
      const loginBtn = document.querySelector('.btn-login, a[class*=actLoginBtn], .login-btn');
      if (loginBtn && /登录|登陆/.test(loginBtn.innerText || '')) {
        return { kind: 'auth', detail: 'Ke shows 登录 button — anonymous session' };
      }
      // 2026-08 贝壳新版 SSR:用户名在 .typeShowUser(脱敏手机号如 15****93),
      // 旧锚点 .userNick/.user-name/.myInfo 已下线,故把 .typeShowUser 提到最前。
      const el = document.querySelector('.typeShowUser a span, .typeShowUser a, .userNick, .user-name, .myInfo a, [class*=userNick]');
      const username = (el?.innerText || '').trim();
      if (!username) {
        return { kind: 'auth', detail: 'Ke no user-name DOM anchor — anonymous or SSR failed' };
      }
      return { ok: true, username };
    })()
  `);
  if (probe?.kind === 'auth') throw new AuthRequiredError('ke.com', probe.detail);
  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Ke probe: ${JSON.stringify(probe)}`);
  return { username: probe.username };
}

registerSiteAuthCommands({
  site: 'ke',
  domain: 'ke.com',
  loginUrl: 'https://clogin.ke.com/login/?service=https%3A%2F%2Fwww.ke.com',
  columns: ['username'],
  verify: verifyKeIdentity,
  poll: async (page) => {
    if (!await hasKeSessionCookie(page)) {
      throw new AuthRequiredError('ke.com', 'Waiting for Ke lianjia_token cookie');
    }
    return verifyKeIdentity(page);
  },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-run the command — transient SSR failure often resolves on retry
  2. Re-login via the ke auth login flow to refresh the session
  3. Inspect https://www.ke.com/ in the browser: if logged in but no username element, the adapter's DOM selectors are stale — update them in clis/ke/auth.js
  4. Increase the wait (page.wait) if the header renders late

Example fix

// before
const el = document.querySelector('.userNick, .user-name, .myInfo a');
// after (match current SSR markup)
const el = document.querySelector('.typeShowUser a span, .typeShowUser a, .userNick, .user-name, .myInfo a, [class*=userNick]');
Defensive patterns

Strategy: try-catch

Validate before calling

const probe = await page.evaluate(`(() => {
  const el = document.querySelector('.typeShowUser a span, .typeShowUser a, .userNick, .user-name, .myInfo a, [class*=userNick]');
  return el ? (el.innerText || '').trim() : '';
})()`);
if (!probe) console.warn('username anchor not found — SSR may have failed; retry or re-login');

Type guard

function hasUsernameAnchor(doc = document) {
  const el = doc.querySelector('.typeShowUser a span, .typeShowUser a, .userNick, .user-name, .myInfo a, [class*=userNick]');
  return typeof el?.innerText === 'string' && el.innerText.trim().length > 0;
}

Try / catch

try {
  const { username } = await keVerify(page);
} catch (e) {
  if (/no user-name DOM anchor/.test(e.message)) {
    await page.reload(); await page.wait(3);   // transient SSR failure: retry once
    return keVerify(page);
  }
  throw e;
}

Prevention

When it happens

Trigger: Cookie exists but the page shows a 登录-free header without any username element; ke.com SSR/layout change renames or removes the CSS anchors; page.goto to https://www.ke.com/ returned an error/blank page; slow render so the header wasn't in DOM after the 2s wait.

Common situations: Beike frontend redeploy changes header markup (as happened with the 2026-08 .typeShowUser SSR migration); network hiccup yields partial SSR; logged-in cookie but server treats the session as anonymous.

Related errors


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