jackwener/OpenCLI · critical · AuthRequiredError
Cookie 已过期!请在当前 Chrome 浏览器中重新登录 BOSS 直聘。
Error message
Cookie 已过期!请在当前 Chrome 浏览器中重新登录 BOSS 直聘。
What it means
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.
Source
Thrown at clis/boss/utils.js:58
*/
export async function navigateToChat(page, waitSeconds = 2) {
await page.goto(CHAT_URL);
await page.wait({ time: waitSeconds });
}
/**
* Navigate to a custom BOSS page (for search/detail that use different pages).
*/
export async function navigateTo(page, url, waitSeconds = 1) {
await page.goto(url);
await page.wait({ time: waitSeconds });
}
/**
* Check if an API response indicates cookie expiry and throw a clear error.
* Call this after every BOSS API response with a non-zero code.
*/
export function checkAuth(data) {
if (COOKIE_EXPIRED_CODES.has(data.code)) {
throw new AuthRequiredError(BOSS_DOMAIN, COOKIE_EXPIRED_MSG);
}
}
function checkEnvironment(data) {
const message = String(data.message || '').toLowerCase();
if (data.code === AMBIGUOUS_AUTH_CODE &&
ENVIRONMENT_REJECTED_MARKERS.some((marker) => message.includes(marker.toLowerCase()))) {
throw new CommandExecutionError(`Boss rejected the current browser environment: ${data.message || 'Unknown error'} (code=${data.code})`, '重新登录通常无法解决此问题。请保留当前页面,稍后重试,并在问题持续时上报完整错误信息。');
}
}
/**
* Map BOSS code=24 ("请切换身份后再试") to a typed AuthRequiredError.
* Recruiter-only commands (recommend, joblist, stats, resume, mark,
* exchange, invite, greet, batchgreet) have no geek-side equivalent;
* surfacing this as a generic COMMAND_EXEC hides what the user must do.
* chatlist / chatmsg avoid this path by using `allowNonZero: true` and
* branching to the geek-side fetch when they see code 24.
*/
function checkRecruiterSide(data) {View on GitHub (pinned to 49907e53dc)
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.
Example fix
// before bossFetch(page, url) // -> code 7 -> AuthRequiredError // after await navigateToChat(page); // ensure logged in first: log in via QR in the driven Chrome, then retry
Defensive patterns
Strategy: try-catch
Validate before calling
const data = await bossFetch(page, probeUrl, { allowNonZero: true });
if ([7, 37].includes(data.code)) {
console.error('Session expired: log in to zhipin.com in the automation Chrome first.');
process.exit(1);
} Type guard
function isCookieExpired(data) {
return !!data && typeof data === 'object' && [7, 37].includes(data.code) &&
!/环境|abnormal/i.test(String(data.message || ''));
} Try / catch
try {
await runBossCommand();
} catch (e) {
if (e instanceof AuthRequiredError) {
console.error('Please log in to BOSS 直聘 in the automation Chrome, then retry.');
process.exit(1);
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 1point3acres Discuz *_auth cookie missing
- 需要登录一亩三分地后再使用该命令
- ChatGPT project requires a logged-in ChatGPT session.
- Claude requires a logged-in browser session.
- dianping.com
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/834a61b3398040b7.
Report an issue: GitHub.