{"record":{"id":"853fea3e42120c8b","repo":"jackwener/OpenCLI","slug":"unexpected-toutiao-probe-json-stringify-probe","errorCode":null,"errorMessage":"Unexpected Toutiao probe: ${JSON.stringify(probe)}","messagePattern":"Unexpected Toutiao probe: (.+?)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/toutiao/auth.js","lineNumber":53,"sourceCode":"          for (const v of Object.values(node)) if (v && typeof v === 'object') stack.push(v);\n        }\n      } catch {}\n      if (!userId) {\n        const ssoUid = (document.cookie.split('; ').find(c => c.startsWith('sso_uid=')) || '').split('=')[1] || '';\n        if (ssoUid) userId = ssoUid;\n      }\n      if (!nickname) {\n        const el = document.querySelector('.user-name, .header-username, .avatar-name, [class*=\"userName\"]');\n        nickname = (el?.innerText || '').trim();\n      }\n      if (!userId) {\n        return { kind: 'auth', detail: 'Toutiao dashboard rendered but no user_id surface — stale session' };\n      }\n      return { ok: true, user_id: userId, nickname };\n    })()\n  `);\n  if (probe?.kind === 'auth') throw new AuthRequiredError('toutiao.com', probe.detail);\n  if (!probe?.ok) throw new CommandExecutionError(`Unexpected Toutiao probe: ${JSON.stringify(probe)}`);\n  return { user_id: probe.user_id, nickname: probe.nickname };\n}\n\nregisterSiteAuthCommands({\n  site: 'toutiao',\n  domain: 'toutiao.com',\n  loginUrl: 'https://mp.toutiao.com/auth/page/login',\n  columns: ['user_id', 'nickname'],\n  quickCheck: hasToutiaoSessionCookie,\n  verify: verifyToutiaoIdentity,\n  poll: async (page) => {\n    if (!await hasToutiaoSessionCookie(page)) {\n      throw new AuthRequiredError('toutiao.com', 'Waiting for Toutiao sessionid cookie');\n    }\n    return verifyToutiaoIdentity(page);\n  },\n});\n","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/toutiao/auth.js#L35-L71","documentation":"CommandExecutionError thrown when the in-page probe result is neither {kind:'auth'} nor {ok:true} — including null/undefined — i.e. an unrecognized shape. It guards against silently returning garbage identity data when page.evaluate fails or the page script returns something unexpected.","triggerScenarios":"Calling toutiao auth verify when page.evaluate returns null/undefined (script blocked by CSP, navigation mid-evaluation, driver quirk) or a malformed object whose kind is not 'auth' and ok is not true.","commonSituations":"Browser automation driver version mismatch where string-script evaluate returns undefined; mp.toutiao.com crashing or being replaced by an error/anti-bot page during evaluation; extensions or CSP stripping injected scripts; network drop leaving the page on about:blank.","solutions":["Re-run the command — transient page-load/navigation races are the most common cause of a null probe.","Inspect the JSON embedded in the error message; it shows exactly what the probe returned.","Verify your driver supports evaluate of stringified IIFEs (check Playwright/Puppeteer version) and that nothing blocks inline scripts on mp.toutiao.com.","Ensure the page finished loading at mp.toutiao.com before verify runs (the flow waits only 2s; slow environments need more).","If the failure persists after a site change, update the probe's return contract in clis/toutiao/auth.js."],"exampleFix":"// before\nif (!probe?.ok) throw new CommandExecutionError(`Unexpected Toutiao probe: ${JSON.stringify(probe)}`);\n// after: retry once before failing\nif (!probe?.ok) {\n  await page.wait(3);\n  probe = await page.evaluate(PROBE_SNIPPET);\n  if (!probe?.ok && probe?.kind !== 'auth') {\n    throw new CommandExecutionError(`Unexpected Toutiao probe: ${JSON.stringify(probe)}`);\n  }\n}","handlingStrategy":"try-catch","validationCode":"if (!page.url().includes('mp.toutiao.com')) {\n  await page.goto('https://mp.toutiao.com/');\n}\nif (typeof page.evaluate !== 'function') {\n  throw new Error('Browser driver does not support page.evaluate — required for the toutiao probe');\n}","typeGuard":"function isSuccessfulProbe(probe) {\n  return !!probe && typeof probe === 'object' && probe.ok === true &&\n    typeof probe.user_id === 'string' && probe.user_id.length > 0;\n}","tryCatchPattern":"try {\n  const identity = await toutiaoAuthVerify(page);\n} catch (err) {\n  if (err.name === 'CommandExecutionError' && err.message.startsWith('Unexpected Toutiao probe')) {\n    await new Promise(r => setTimeout(r, 3000));\n    return toutiaoAuthVerify(page); // single retry for transient navigation races\n  }\n  throw err;\n}","preventionTips":["Parse the JSON embedded in the error message to see exactly what the probe returned (usually null or an unexpected shape).","Retry once before failing — null/undefined probes are usually transient load/navigation races.","Keep Playwright/Puppeteer updated; driver/protocol mismatches can make evaluate silently return undefined.","Ensure no extensions or CSP changes block injected scripts on mp.toutiao.com.","Check the page is fully loaded (not about:blank or an error page) before verify runs."],"tags":["browser-automation","unexpected-state","probe","toutiao"],"backgroundTag":"unexpected-probe-result","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}