jackwener/OpenCLI · critical · CommandExecutionError
Boss rejected the current browser environment: ${data.messag
Error message
Boss rejected the current browser environment: ${data.message || 'Unknown error'} (code=${data.code}) What it means
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).
Source
Thrown at clis/boss/utils.js:65
*/
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) {
if (data.code === IDENTITY_MISMATCH_CODE) {
throw new AuthRequiredError(BOSS_DOMAIN, RECRUITER_ONLY_MSG);
}
}
/**
* Throw if the API response is not code 0.
* Checks for cookie expiry first, then identity mismatch, then throwsView on GitHub (pinned to 49907e53dc)
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.
Example fix
// before
for (const p of pages) { await fetchFriendList(page, { pageNum: p }); } // rapid loop triggers risk control
// after
for (const p of pages) { await fetchFriendList(page, { pageNum: p }); await page.wait({ time: 2 }); } Defensive patterns
Strategy: retry
Validate before calling
const probe = await bossFetch(page, probeUrl, { allowNonZero: true });
if (probe.code === 37 && /环境|abnormal environment/i.test(String(probe.message || ''))) {
console.error('Environment flagged by risk control: disable VPN, use normal Chrome, wait and retry.');
process.exit(1);
} Type guard
function isEnvironmentRejected(data) {
return !!data && typeof data === 'object' && data.code === 37 &&
['环境存在异常', '环境异常', 'abnormal environment'].some((m) => String(data.message || '').toLowerCase().includes(m.toLowerCase()));
} Try / catch
try {
await runBossCommand();
} catch (e) {
if (e instanceof CommandExecutionError && /rejected the current browser environment/.test(e.message)) {
await sleep(15 * 60 * 1000); // back off, keep page open, then retry
return runBossCommand();
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Xianyu item detail is blocked by verification or risk contro
- item.jd.com
- Xianyu blocked by verification / risk control
- SECURITY_BLOCK
- 响应不是有效 JSON
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4a22daddf6d4ca6a.
Report an issue: GitHub.