{"record":{"id":"4a22daddf6d4ca6a","repo":"jackwener/OpenCLI","slug":"boss-rejected-the-current-browser-environment-d","errorCode":null,"errorMessage":"Boss rejected the current browser environment: ${data.message || 'Unknown error'} (code=${data.code})","messagePattern":"Boss rejected the current browser environment: (.+?) \\(code=(.+?)\\)","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"critical","filePath":"clis/boss/utils.js","lineNumber":65,"sourceCode":" */\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) {\n    if (data.code === IDENTITY_MISMATCH_CODE) {\n        throw new AuthRequiredError(BOSS_DOMAIN, RECRUITER_ONLY_MSG);\n    }\n}\n/**\n * Throw if the API response is not code 0.\n * Checks for cookie expiry first, then identity mismatch, then throws","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/boss/utils.js#L47-L83","documentation":"checkEnvironment fires when the API returns code 37 AND the message contains an environment-rejection marker (环境存在异常 / 环境异常 / abnormal environment). BOSS's risk-control system considers the browser fingerprint or network environment suspicious and refuses the request. The library throws CommandExecutionError with guidance that re-login will NOT help, distinguishing it from ordinary cookie expiry (also code 37).","triggerScenarios":"bossFetch response with code=37 and message matching one of ENVIRONMENT_REJECTED_MARKERS — BOSS risk control flagging the automated/headless-looking browser, a datacenter IP/VPN, or abnormal request cadence.","commonSituations":"Running from a VPS/cloud IP; using a VPN or proxy; headless or non-standard Chrome fingerprint; issuing too many rapid requests; previously rate-limited account/IP.","solutions":["Pause and retry later (minutes to hours) — the rejection is often transient; keep the current page open as the error advises.","Disable VPN/proxy or switch to a residential network and retry with the same Chrome profile.","Use a normal (non-headless) Chrome with the user's regular profile and cookies.","Slow down request frequency / add delays between calls to avoid tripping risk control.","If it persists, report the full error message — repeated rejection may require contacting BOSS support or account review."],"exampleFix":"// before\nfor (const p of pages) { await fetchFriendList(page, { pageNum: p }); } // rapid loop triggers risk control\n// after\nfor (const p of pages) { await fetchFriendList(page, { pageNum: p }); await page.wait({ time: 2 }); }","handlingStrategy":"retry","validationCode":"const probe = await bossFetch(page, probeUrl, { allowNonZero: true });\nif (probe.code === 37 && /环境|abnormal environment/i.test(String(probe.message || ''))) {\n  console.error('Environment flagged by risk control: disable VPN, use normal Chrome, wait and retry.');\n  process.exit(1);\n}","typeGuard":"function isEnvironmentRejected(data) {\n  return !!data && typeof data === 'object' && data.code === 37 &&\n    ['环境存在异常', '环境异常', 'abnormal environment'].some((m) => String(data.message || '').toLowerCase().includes(m.toLowerCase()));\n}","tryCatchPattern":"try {\n  await runBossCommand();\n} catch (e) {\n  if (e instanceof CommandExecutionError && /rejected the current browser environment/.test(e.message)) {\n    await sleep(15 * 60 * 1000); // back off, keep page open, then retry\n    return runBossCommand();\n  }\n  throw e;\n}","preventionTips":["Avoid datacenter IPs, VPNs, and headless browsers for BOSS automation","Throttle request rate with delays between calls","Reuse one stable, logged-in Chrome profile rather than fresh profiles","Keep the browser page open and back off for a while after a rejection"],"tags":["risk-control","anti-bot","environment-rejected","blocked"],"backgroundTag":"bot-environment-rejected","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}