{"record":{"id":"881da2ed8558b3f1","repo":"jackwener/OpenCLI","slug":"unexpected-jd-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected JD probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected JD probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/jd/auth.js","lineNumber":29,"sourceCode":"  if (!await hasJdSessionCookie(page)) {\n    throw new AuthRequiredError('jd.com', 'JD pin / thor cookie missing');\n  }\n  await page.goto('https://home.jd.com/');\n  await page.wait(3);\n  const probe = await page.evaluate(`\n    (() => {\n      const pinCookie = (document.cookie.split('; ').find(c => c.startsWith('pin=')) || '').split('=')[1] || '';\n      const decoded = pinCookie ? decodeURIComponent(pinCookie) : '';\n      if (!decoded) {\n        return { kind: 'auth', detail: 'JD pin cookie empty after decode' };\n      }\n      const nickEl = document.querySelector('.user-info, #aliveUserName, .name, .user-name');\n      const nickname = (nickEl && nickEl.textContent && nickEl.textContent.trim()) || '';\n      return { ok: true, pin: decoded, nickname };\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('jd.com', probe.detail);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected JD probe: ${JSON.stringify(probe)}`);\n  return { pin: probe.pin, nickname: probe.nickname };\n}\n\nregisterSiteAuthCommands({\n  site: 'jd',\n  domain: 'jd.com',\n  loginUrl: 'https://passport.jd.com/new/login.aspx',\n  columns: ['pin', 'nickname'],\n  quickCheck: hasJdSessionCookie,\n  verify: verifyJdIdentity,\n  poll: async (page) => {\n    if (!await hasJdSessionCookie(page)) {\n      throw new AuthRequiredError('jd.com', 'Waiting for JD pin / thor cookie');\n    }\n    return verifyJdIdentity(page);\n  },\n});\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/jd/auth.js#L11-L47","documentation":"verifyJdIdentity throws CommandExecutionError('Unexpected JD probe: ...') when the in-page evaluate on home.jd.com returns a payload without ok:true and without kind:'auth' — an unrecognized probe result. This is a defensive guard against unexpected DOM/JS shapes rather than an auth problem.","triggerScenarios":"The probe script's page.evaluate returns null/undefined (page failed to render), or returns an object lacking both ok and kind fields — e.g. JD changed its home page markup, an anti-bot interstitial replaced the page, or the page navigated away before evaluation.","commonSituations":"JD served a captcha/anti-bot page instead of home.jd.com; slow network left the page unrendered when evaluate ran; JD frontend redesign moved the .user-info/#aliveUserName selectors; iframe/embedded layout changes.","solutions":["Retry the command once — transient rendering failures often resolve","Log in to JD and confirm home.jd.com shows your account normally in the browser","Check for JD anti-bot/captcha pages and complete any challenge manually","Update the opencli package in case JD changed its page structure (selector drift)"],"exampleFix":"// before\nconst me = await jdWhoami();\n// after\ntry {\n  const me = await jdWhoami();\n} catch (e) {\n  if (e.code === 'COMMAND_EXEC' && /Unexpected JD probe/.test(e.message)) {\n    await sleep(3000); // let the page settle, then retry\n    const me = await jdWhoami();\n  }\n}","handlingStrategy":"retry","validationCode":"// ensure page settled before probing\nawait page.goto('https://home.jd.com/');\nawait page.waitForSelector('.user-info, #aliveUserName, .name, .user-name', { timeout: 10000 }).catch(() => {});","typeGuard":"function isUnexpectedProbe(e) {\n  return e?.code === 'COMMAND_EXEC' && /Unexpected JD probe/.test(e.message);\n}","tryCatchPattern":"for (let i = 0; i < 3; i++) {\n  try { return await jdVerify(); }\n  catch (e) { if (!isUnexpectedProbe(e) || i === 2) throw e; await sleep(3000); }\n}","preventionTips":["Add settle waits before page.evaluate probes","Watch for JD anti-bot/captcha pages and solve them manually","Pin/update opencli versions when JD changes its frontend","Log full probe payloads to diagnose new page shapes"],"tags":["jd","probe","unexpected-response","anti-bot"],"backgroundTag":"unexpected-probe-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}