{"record":{"id":"c0c3da2e81e8de6e","repo":"jackwener/OpenCLI","slug":"unexpected-ke-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected Ke probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected Ke probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/ke/auth.js","lineNumber":32,"sourceCode":"  await page.wait(2);\n  const probe = await page.evaluate(`\n    (() => {\n      const loginBtn = document.querySelector('.btn-login, a[class*=actLoginBtn], .login-btn');\n      if (loginBtn && /登录|登陆/.test(loginBtn.innerText || '')) {\n        return { kind: 'auth', detail: 'Ke shows 登录 button — anonymous session' };\n      }\n      // 2026-08 贝壳新版 SSR：用户名在 .typeShowUser（脱敏手机号如 15****93），\n      // 旧锚点 .userNick/.user-name/.myInfo 已下线，故把 .typeShowUser 提到最前。\n      const el = document.querySelector('.typeShowUser a span, .typeShowUser a, .userNick, .user-name, .myInfo a, [class*=userNick]');\n      const username = (el?.innerText || '').trim();\n      if (!username) {\n        return { kind: 'auth', detail: 'Ke no user-name DOM anchor — anonymous or SSR failed' };\n      }\n      return { ok: true, username };\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('ke.com', probe.detail);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Ke probe: ${JSON.stringify(probe)}`);\n  return { username: probe.username };\n}\n\nregisterSiteAuthCommands({\n  site: 'ke',\n  domain: 'ke.com',\n  loginUrl: 'https://clogin.ke.com/login/?service=https%3A%2F%2Fwww.ke.com',\n  columns: ['username'],\n  verify: verifyKeIdentity,\n  poll: async (page) => {\n    if (!await hasKeSessionCookie(page)) {\n      throw new AuthRequiredError('ke.com', 'Waiting for Ke lianjia_token cookie');\n    }\n    return verifyKeIdentity(page);\n  },\n});\n","sourceCodeStart":14,"sourceCodeEnd":49,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/ke/auth.js#L14-L49","documentation":"The in-page identity probe returned something that is neither {kind:'auth'} nor {ok:true} — e.g. null/undefined (evaluate failed or returned nothing) or an unexpected object shape. verifyKeIdentity throws CommandExecutionError with the probe serialized, since this indicates an adapter/runtime failure rather than a normal unauthenticated state.","triggerScenarios":"page.evaluate throws or returns undefined (navigation destroyed the execution context, CSP blocks eval, page closed); the probe script itself errors and the host swallows it into null; a middleware/interceptor returns a non-standard value from evaluate.","commonSituations":"Page navigated or was redirected during the 2s wait, invalidating the evaluation context; browser automation driver version mismatch making evaluate return undefined; anti-bot script neutralizing injected scripts.","solutions":["Re-run the command; transient navigation races often resolve","Check the serialized probe in the message to see what actually came back (null vs object)","Ensure the page stays on www.ke.com (no redirect) during verify; re-goto before probing","Update the page driver/automation library if evaluate is systematically broken"],"exampleFix":"// before\nconst probe = await page.evaluate(script); // undefined after navigation\nif (!probe?.ok) throw new CommandExecutionError(`Unexpected Ke probe: ${JSON.stringify(probe)}`);\n// after\nlet probe = await page.evaluate(script);\nif (probe == null) { await page.goto('https://www.ke.com/'); await page.wait(2); probe = await page.evaluate(script); }","handlingStrategy":"try-catch","validationCode":"const probe = await page.evaluate(script).catch(err => ({ __evalError: String(err) }));\nif (probe == null || probe.__evalError) {\n  console.warn('in-page probe failed; re-navigating before retry');\n  await page.goto('https://www.ke.com/');\n}","typeGuard":"function isWellFormedProbe(p) {\n  return p != null && (('ok' in p && p.ok === true) || (p.kind === 'auth' && typeof p.detail === 'string'));\n}","tryCatchPattern":"try {\n  await keVerify(page);\n} catch (e) {\n  if (/Unexpected Ke probe/.test(e.message)) {\n    await page.goto('https://www.ke.com/');\n    await page.wait(3);\n    return keVerify(page); // single retry after re-navigation\n  }\n  throw e;\n}","preventionTips":["Never navigate the page while a verify/probe is running","Retry once after re-goto — evaluate failures are usually navigation races","Keep the automation driver and browser versions in sync","Log the serialized probe payload (already in the message) for diagnosis"],"tags":["automation","evaluate","runtime","ke"],"backgroundTag":"browser-context-lost","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}