{"record":{"id":"1c50152d15732e8d","repo":"jackwener/OpenCLI","slug":"jimeng-whoami-failed-probe-detail","errorCode":null,"errorMessage":"Jimeng whoami failed: ${probe.detail}","messagePattern":"Jimeng whoami failed: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/jimeng/auth.js","lineNumber":30,"sourceCode":"    const r = await fetch('/passport/account/info/v2/?aid=513695', { credentials: 'include', headers: { Accept: 'application/json' } });\n    if (r.status === 401 || r.status === 403) return { kind: 'auth', detail: 'Jimeng passport HTTP ' + r.status };\n    if (!r.ok) return { kind: 'http', httpStatus: r.status };\n    const d = await r.json();\n    const u = d && d.data;\n    if (!u || !u.user_id || u.is_visitor_account) return { kind: 'auth', detail: 'Jimeng passport returned a visitor account (anonymous)' };\n    return { ok: true, user_id: String(u.user_id_str || u.user_id), screen_name: String(u.screen_name || u.name || '') };\n  } catch (e) {\n    return { kind: 'exception', detail: String(e && e.message || e) };\n  }\n})()`;\n\nasync function verifyJimengIdentity(page) {\n  await page.goto('https://jimeng.jianying.com/ai-tool/generate?type=image&workspace=0');\n  await page.wait(2);\n  const probe = await page.evaluate(WHOAMI_PROBE);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('jimeng.jianying.com', probe.detail);\n  if (probe?.kind === 'http') throw new CommandExecutionError(`HTTP ${probe.httpStatus} from Jimeng passport`);\n  if (probe?.kind === 'exception') throw new CommandExecutionError(`Jimeng whoami failed: ${probe.detail}`);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Jimeng probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, screen_name: probe.screen_name };\n}\n\nregisterSiteAuthCommands({\n  site: 'jimeng',\n  domain: 'jimeng.jianying.com',\n  loginUrl: 'https://jimeng.jianying.com/',\n  columns: ['user_id', 'screen_name'],\n  verify: verifyJimengIdentity,\n  poll: async (page) => {\n    const probe = await page.evaluate(WHOAMI_PROBE);\n    if (!probe?.ok) throw new AuthRequiredError('jimeng.jianying.com', 'Waiting for Jimeng login');\n    return { user_id: probe.user_id, screen_name: probe.screen_name };\n  },\n});\n","sourceCodeStart":12,"sourceCodeEnd":47,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/jimeng/auth.js#L12-L47","documentation":"If the WHOAMI_PROBE script itself throws while executing in the page (kind 'exception'), verifyJimengIdentity wraps it as CommandExecutionError('Jimeng whoami failed: <detail>'). The identity check could not even complete, indicating a scripting or page-state problem rather than an auth or HTTP issue.","triggerScenarios":"page.evaluate(WHOAMI_PROBE) rejects or the probe's try/catch returns kind 'exception' — e.g. the page failed to load fully, the probe references APIs removed from the page context, CSP blocks the fetch, or the page was navigated away mid-probe.","commonSituations":"Page still loading or redirected to another URL when the probe runs; Jimeng front-end update changing global objects the probe depends on; browser extension or CSP interfering; stale tab with an error page.","solutions":["Reload the Jimeng page and ensure it fully loads before the probe runs (increase the wait after page.goto)","Read probe.detail in the message for the underlying JS error","Verify the page URL is jimeng.jianying.com (not a redirect/error page) before evaluating","Update the CLI/WHOAMI_PROBE if Jimeng changed its page structure","Disable extensions that inject scripts or block requests on the page"],"exampleFix":"// before\nconst probe = await page.evaluate(WHOAMI_PROBE);\n// after\nawait page.goto('https://jimeng.jianying.com/ai-tool/generate?type=image&workspace=0');\nawait page.wait(5); // give SPA more time before probing\nconst probe = await page.evaluate(WHOAMI_PROBE);","handlingStrategy":"try-catch","validationCode":"if (!page.url().includes('jimeng.jianying.com')) throw new Error('Probe must run on jimeng.jianying.com — navigate first');","typeGuard":"function isProbeException(err) {\n  return err instanceof CommandExecutionError && err.message.startsWith('Jimeng whoami failed:');\n}","tryCatchPattern":"try {\n  const identity = await verifyJimengIdentity(page);\n} catch (err) {\n  if (isProbeException(err)) {\n    console.error('In-page probe crashed:', err.message); // inspect detail, reload page and retry\n  }\n  throw err;\n}","preventionTips":["Wait for the SPA to finish loading before page.evaluate","Assert the page URL is on jimeng.jianying.com before probing","Keep WHOAMI_PROBE in sync with Jimeng's page structure","Return only serializable values from in-page scripts"],"tags":["browser-automation","jimeng","script-error","page-evaluate"],"backgroundTag":"page-evaluate-failed","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}