{"record":{"id":"96f8d204c0477abb","repo":"jackwener/OpenCLI","slug":"waiting-for-zhihu-z-c0-cookie","errorCode":null,"errorMessage":"Waiting for Zhihu z_c0 cookie","messagePattern":"Waiting for Zhihu z_c0 cookie","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"warning","filePath":"clis/zhihu/auth.js","lineNumber":55,"sourceCode":"    throw new AuthRequiredError('www.zhihu.com', 'Zhihu /api/v4/me returned no url_token — anonymous session');\n  }\n  return {\n    url_token: String(data.url_token),\n    name: String(data.name ?? ''),\n    uid: String(data.uid ?? data.id ?? ''),\n  };\n}\n\nregisterSiteAuthCommands({\n  site: 'zhihu',\n  domain: 'www.zhihu.com',\n  loginUrl: 'https://www.zhihu.com/signin',\n  columns: ['url_token', 'name', 'uid'],\n  quickCheck: hasZhihuAuthCookie,\n  verify: verifyZhihuIdentity,\n  poll: async (page) => {\n    if (!await hasZhihuAuthCookie(page)) {\n      throw new AuthRequiredError('www.zhihu.com', 'Waiting for Zhihu z_c0 cookie');\n    }\n    return verifyZhihuIdentity(page);\n  },\n});\n","sourceCodeStart":37,"sourceCodeEnd":60,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/zhihu/auth.js#L37-L60","documentation":"The zhihu login flow polls the browser until authentication completes; its poll function re-checks for the z_c0 cookie and, if still absent, throws AuthRequiredError 'Waiting for Zhihu z_c0 cookie'. It signals that the user has not finished signing in yet and polling should continue/await login.","triggerScenarios":"During interactive login, each poll fires before the user completes the sign-in (QR scan, SMS code, password) — the cookie is simply not set yet. Also fires if login silently failed (user closed the form, wrong credentials, captcha not solved).","commonSituations":"User takes too long to scan the QR code; Zhihu shows a captcha or verification step that blocks completion; automation profile blocked from persisting cookies so login never 'sticks'.","solutions":["Complete the login in the automated browser window (scan QR / enter code) — the error clears on the next successful poll.","If the login form shows a captcha or verification challenge, solve it in the browser.","If polling repeatedly fails after successful sign-in, check that the profile persists cookies (user-data-dir) and the URL scope is www.zhihu.com.","Treat this error as 'not yet logged in' — retry/poll rather than treating it as fatal, unless it persists."],"exampleFix":"// before\nawait zhihuLogin(); // AuthRequiredError: Waiting for Zhihu z_c0 cookie\n// after\ntry {\n  await zhihuLogin({ timeoutMs: 120_000 }); // give user time to scan QR\n} catch (e) {\n  if (String(e.message).includes('z_c0')) {\n    console.error('Sign-in not completed in time. Re-run and finish login in the browser.');\n  }\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"const cookies = await page.getCookies({ url: 'https://www.zhihu.com' });\nconst done = cookies.some(c => c.name === 'z_c0' && c.value);\nif (!done) console.log('Waiting for you to complete sign-in in the browser...');","typeGuard":"function loginComplete(cookies) { return Array.isArray(cookies) && cookies.some(c => c.name === 'z_c0' && !!c.value); }","tryCatchPattern":"let me;\nwhile (!me) {\n  try { me = await poll(); }\n  catch (e) { if (!String(e.message).includes('z_c0')) throw e; await sleep(1500); } // keep waiting for login\n}","preventionTips":["Complete the QR/SMS sign-in promptly inside the automated browser","Use a generous login timeout (e.g. 2 minutes) when a human must interact","Solve any captcha/verification challenge shown during login","Ensure cookies persist (user-data-dir) so login completes across polls"],"tags":["authentication","login","zhihu","cookie","polling"],"backgroundTag":"auth-login-pending","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}