{"record":{"id":"6e477b4c3fec8dbc","repo":"jackwener/OpenCLI","slug":"maimai-whoami-failed-probe-detail","errorCode":null,"errorMessage":"Maimai whoami failed: ${probe.detail}","messagePattern":"Maimai whoami failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/maimai/auth.js","lineNumber":35,"sourceCode":"    if (!user || !user.id) return { kind: 'auth', detail: 'Maimai userObj missing from page (anonymous)' };\n    return {\n      ok: true,\n      user_id: String(user.id),\n      name: String(user.name || ''),\n      company: String(user.company || ''),\n    };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nasync function verifyMaimaiIdentity(page) {\n  await page.goto('https://maimai.cn/');\n  await page.wait(2);\n  const probe = await page.evaluate(WHOAMI_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('maimai.cn', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Maimai`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Maimai whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Maimai probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, name: probe.name, company: probe.company };\n}\n\nregisterSiteAuthCommands({\n  site: 'maimai',\n  domain: 'maimai.cn',\n  loginUrl: 'https://maimai.cn/',\n  columns: ['user_id', 'name', 'company'],\n  verify: verifyMaimaiIdentity,\n  poll: verifyMaimaiIdentity,\n});\n","sourceCodeStart":17,"sourceCodeEnd":48,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/maimai/auth.js#L17-L48","documentation":"Thrown at clis/maimai/auth.js:35 when the WHOAMI_PROBE's internal try/catch caught a JavaScript exception in the page and returned kind:'exception'. The message embeds the browser-side error (probe.detail). It means the login-verification script itself crashed while scanning page scripts or parsing userObj — not that you're logged out.","triggerScenarios":"page.evaluate throwing inside the probe: DOM APIs unavailable, scripts enumeration failing, JSON.parse hitting malformed content that escapes the inner try, or the page context being destroyed by a redirect/navigation during the 2s wait.","commonSituations":"Maimai homepage redirects mid-probe (SPA navigation destroying context); browser extension injecting scripts that break enumeration; maimai.cn changing its inline-script format so parsing throws; headless browser quirks.","solutions":["Re-run the check — transient navigation/redirect races often resolve on retry","Open maimai.cn manually and confirm the page renders normally","Increase the wait after page.goto so redirects settle before probing","If maimai changed the userObj script format, update the WHOAMI_PROBE regex","Check for interfering browser extensions or run a clean profile"],"exampleFix":"// before\nawait page.goto('https://maimai.cn/');\nawait page.wait(2);\nconst probe = await page.evaluate(WHOAMI_PROBE);\n// after\nawait page.goto('https://maimai.cn/', { waitUntil: 'networkidle' });\nawait page.wait(5); // let redirects/spa routing settle before probing\nconst probe = await page.evaluate(WHOAMI_PROBE);","handlingStrategy":"retry","validationCode":"// ensure the page is on maimai.cn and settled before probing\nif (!page.url().includes('maimai.cn')) await page.goto('https://maimai.cn/');\nawait page.wait(3);","typeGuard":"function isProbeException(e) {\n  return e instanceof Error && e.message.startsWith('Maimai whoami failed:');\n}","tryCatchPattern":"try {\n  await verifyMaimaiIdentity(page);\n} catch (e) {\n  if (isProbeException(e)) {\n    await page.reload();\n    await page.wait(5);\n    return verifyMaimaiIdentity(page); // single retry\n  }\n  throw e;\n}","preventionTips":["Reload and re-probe once before giving up — redirect races are common","Wait for page stability (networkidle) before page.evaluate","Test in a clean browser profile without extensions","Keep WHOAMI_PROBE in sync with maimai's inline-script format"],"tags":["browser-automation","page-evaluate","runtime-error"],"backgroundTag":"page-evaluate-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}