jackwener/OpenCLI · error · AuthRequiredError
Xiaohongshu collection page requires login; re-login to xiao
Error message
Xiaohongshu collection page requires login; re-login to xiaohongshu.com and retry.
What it means
throwIfLoginWall evaluates an in-page script that detects xiaohongshu's login wall (payload === true). When detected, it throws AuthRequiredError telling the user to re-login to www.xiaohongshu.com. The library refuses to scrape collection pages behind the wall since responses would be login forms rather than data.
Source
Thrown at clis/xiaohongshu/collection-helpers.js:182
const userStore = window.__INITIAL_STATE__?.user;
const loggedInVal = userStore ? (userStore.loggedIn?._value ?? userStore.loggedIn) : undefined;
const bodyText = document.body?.innerText || '';
return Boolean(pathName.indexOf('/login') === 0 || loggedInVal === false || /登录后|请先登录|登录后查看/.test(bodyText));
})()
`;
const CURRENT_LOCATION_JS = `
(() => ({
href: location.href,
hostname: location.hostname,
pathname: location.pathname,
}))()
`;
async function throwIfLoginWall(page) {
const payload = unwrapBrowserResult(await page.evaluate(LOGIN_WALL_JS));
if (payload === true) {
throw new AuthRequiredError('www.xiaohongshu.com', 'Xiaohongshu collection page requires login; re-login to xiaohongshu.com and retry.');
}
}
export async function assertOnCollectionProfile(page, userId) {
await throwIfLoginWall(page);
const payload = unwrapBrowserResult(await page.evaluate(CURRENT_LOCATION_JS));
if (!isObject(payload)) {
throw new CommandExecutionError('xiaohongshu collection page returned malformed location');
}
const hostname = toCleanString(payload.hostname).toLowerCase();
const pathname = toCleanString(payload.pathname);
if (hostname === 'www.xiaohongshu.com' && pathname === '/login') {
throw new AuthRequiredError('xiaohongshu collection page requires login');
}
const expectedPath = `/user/profile/${toCleanString(userId)}`;
if (hostname !== 'www.xiaohongshu.com' || pathname !== expectedPath) {
throw new CommandExecutionError(`xiaohongshu collection landed on unexpected page: ${toCleanString(payload.href) || `${hostname}${pathname}`}`);
}View on GitHub (pinned to 49907e53dc)
Solutions
- Log in to www.xiaohongshu.com in the automation browser and retry
- Re-run your browser login/refresh-session helper before fetching
- Persist cookies so sessions survive across runs
- Check that the login-wall detection is not a false positive from an anti-bot interstitial
Example fix
// before
const notes = await fetchXhsCollectionNotes(page, userId); // AuthRequiredError
// after
if (!(await isLoggedInToXhs(page))) {
await performXhsLogin(page); // scripted login or prompt user
}
const notes = await fetchXhsCollectionNotes(page, userId); Defensive patterns
Strategy: retry
Validate before calling
const loginWallDetected = (page) => page.evaluate(() => !!document.querySelector('.login-container, .sign-in-container, [class*="login"]')); Type guard
const looksLoggedIn = (payload) => payload !== true;
Try / catch
try { notes = await fetchXhsCollectionNotes(page, userId); } catch (e) { if (e instanceof AuthRequiredError) { await performXhsLogin(page); notes = await fetchXhsCollectionNotes(page, userId); } else throw e; } Prevention
- Re-login to www.xiaohongshu.com whenever a run starts and cookies are stale
- Persist cookies across runs and refresh them proactively
- Detect short-lived session expiry and re-auth before long scrapes
- Keep scraping pace human-like to avoid forced re-login risk control
When it happens
Trigger: Fetching a user's collection notes while the automation browser's xiaohongshu session is expired or missing; xiaohongshu redirects or overlays the profile page with a login prompt.
Common situations: Session cookies expired (web sessions for xiaohongshu are short-lived); fresh browser profile never logged in; xiaohongshu forced re-login after risk-control flagging.
Related errors
- [taxonomy=selector_drift] site=powerchina command=search log
- xiaohongshu collection page requires login
- Note comments require login
- 1point3acres Discuz *_auth cookie missing
- 需要登录一亩三分地后再使用该命令
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/60dfd06f12672282.
Report an issue: GitHub.