{"record":{"id":"834a61b3398040b7","repo":"jackwener/OpenCLI","slug":"cookie-chrome-boss","errorCode":null,"errorMessage":"Cookie 已过期！请在当前 Chrome 浏览器中重新登录 BOSS 直聘。","messagePattern":"Cookie 已过期！请在当前 Chrome 浏览器中重新登录 BOSS 直聘。","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"critical","filePath":"clis/boss/utils.js","lineNumber":58,"sourceCode":" */\nexport async function navigateToChat(page, waitSeconds = 2) {\n    await page.goto(CHAT_URL);\n    await page.wait({ time: waitSeconds });\n}\n/**\n * Navigate to a custom BOSS page (for search/detail that use different pages).\n */\nexport async function navigateTo(page, url, waitSeconds = 1) {\n    await page.goto(url);\n    await page.wait({ time: waitSeconds });\n}\n/**\n * Check if an API response indicates cookie expiry and throw a clear error.\n * Call this after every BOSS API response with a non-zero code.\n */\nexport function checkAuth(data) {\n    if (COOKIE_EXPIRED_CODES.has(data.code)) {\n        throw new AuthRequiredError(BOSS_DOMAIN, COOKIE_EXPIRED_MSG);\n    }\n}\nfunction checkEnvironment(data) {\n    const message = String(data.message || '').toLowerCase();\n    if (data.code === AMBIGUOUS_AUTH_CODE &&\n        ENVIRONMENT_REJECTED_MARKERS.some((marker) => message.includes(marker.toLowerCase()))) {\n        throw new CommandExecutionError(`Boss rejected the current browser environment: ${data.message || 'Unknown error'} (code=${data.code})`, '重新登录通常无法解决此问题。请保留当前页面，稍后重试，并在问题持续时上报完整错误信息。');\n    }\n}\n/**\n * Map BOSS code=24 (\"请切换身份后再试\") to a typed AuthRequiredError.\n * Recruiter-only commands (recommend, joblist, stats, resume, mark,\n * exchange, invite, greet, batchgreet) have no geek-side equivalent;\n * surfacing this as a generic COMMAND_EXEC hides what the user must do.\n * chatlist / chatmsg avoid this path by using `allowNonZero: true` and\n * branching to the geek-side fetch when they see code 24.\n */\nfunction checkRecruiterSide(data) {","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/boss/utils.js#L40-L76","documentation":"checkAuth inspects every BOSS API response and throws AuthRequiredError when data.code is 7 or 37 (COOKIE_EXPIRED_CODES), meaning the session cookie in the attached Chrome profile is no longer valid. The library requires a logged-in zhipin.com session because all calls are credentialed XHRs made from the browser page. Re-login in the controlled Chrome instance is the only fix.","triggerScenarios":"Any bossFetch-backed command (friends, joblist, chatlist, recommend, etc.) receiving code 7 or 37 from the wapi endpoint because the zhipin.com cookie in the automation Chrome profile expired or was invalidated.","commonSituations":"Running the CLI after a long idle period; BOSS logging the account out server-side (new device login, password change); wiping the Chrome profile; running on a fresh machine without ever logging in.","solutions":["Open the automation Chrome instance, log in to BOSS 直聘 (scan QR code), then rerun the command.","Confirm the same Chrome profile the library drives is the one you log into (not a separate browser window).","If logins expire unusually fast, check whether another login elsewhere is invalidating the session and avoid concurrent logins."],"exampleFix":"// before\nbossFetch(page, url) // -> code 7 -> AuthRequiredError\n// after\nawait navigateToChat(page); // ensure logged in first: log in via QR in the driven Chrome, then retry","handlingStrategy":"try-catch","validationCode":"const data = await bossFetch(page, probeUrl, { allowNonZero: true });\nif ([7, 37].includes(data.code)) {\n  console.error('Session expired: log in to zhipin.com in the automation Chrome first.');\n  process.exit(1);\n}","typeGuard":"function isCookieExpired(data) {\n  return !!data && typeof data === 'object' && [7, 37].includes(data.code) &&\n    !/环境|abnormal/i.test(String(data.message || ''));\n}","tryCatchPattern":"try {\n  await runBossCommand();\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    console.error('Please log in to BOSS 直聘 in the automation Chrome, then retry.');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Log in and keep the automation Chrome profile's session warm before scripting","Re-login promptly when AuthRequiredError appears; don't retry blindly","Avoid logging into the same account concurrently from other devices/browsers","Probe with an allowNonZero call to detect expiry before batch runs"],"tags":["auth","cookie-expired","login-required"],"backgroundTag":"cookie-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}