jackwener/OpenCLI · error · AuthRequiredError
xiaohongshu collection page requires login
Error message
xiaohongshu collection page requires login
What it means
assertOnCollectionProfile checks the page URL: if the browser is on www.xiaohongshu.com/login, the library throws AuthRequiredError because the collection fetch was redirected to the login page. It is a second, redirect-based login check complementing throwIfLoginWall.
Source
Thrown at clis/xiaohongshu/collection-helpers.js:195
`;
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}`}`);
}
}
async function accumulateInterceptedNotes(page, bucket, fallbackUserId) {
const reqs = await page.getInterceptedRequests();
if (!Array.isArray(reqs)) {
throw new CommandExecutionError('xiaohongshu collection interceptor returned malformed captures');
}
if (Array.isArray(reqs) && reqs.length > 0)
bucket.push(...reqs);
return extractNotesFromResponses(bucket, fallbackUserId);
}
export async function resolveXhsUserId(page, rawId) {View on GitHub (pinned to 49907e53dc)
Solutions
- Re-login to xiaohongshu.com in the automation browser, then retry
- Verify the userId is a public profile your session can view
- Refresh/persist session cookies before each run
- Slow scraping pace to avoid risk-control redirects
Example fix
// before
await page.goto(`/user/profile/${userId}`);
const notes = await fetchXhsCollectionNotes(page, userId); // redirected to /login
// after
if (page.url().includes('/login')) {
await performXhsLogin(page);
await page.goto(`/user/profile/${userId}`);
}
const notes = await fetchXhsCollectionNotes(page, userId); Defensive patterns
Strategy: retry
Validate before calling
const onLoginPage = (page) => { try { const u = new URL(page.url()); return u.hostname === 'www.xiaohongshu.com' && u.pathname === '/login'; } catch { return false; } }; Type guard
const isXhsProfileUrl = (url, userId) => { try { const u = new URL(url); return u.hostname === 'www.xiaohongshu.com' && u.pathname === `/user/profile/${userId}`; } catch { return false; } }; 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
- Verify session validity (e.g. load a known authed endpoint) before scraping
- Persist and refresh cookies between runs
- Treat /login redirects as auth expiry signals and re-auth automatically
- Avoid restricted/private profiles your session cannot view
When it happens
Trigger: Navigating to /user/profile/<userId> results in a redirect to /login because the session is unauthenticated or expired.
Common situations: Expired cookies triggering a server-side redirect; visiting a private/restricted profile that requires auth; xiaohongshu risk-control redirecting suspicious traffic to login.
Related errors
- Xiaohongshu collection page requires login; re-login to xiao
- hotels.ctrip.com
- vacations.ctrip.com
- guazi ${contextHint} hit an anti-bot challenge — Guazi may h
- No chats visible in sidebar. Are you logged in?
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/2cf06d6e06dcebfa.
Report an issue: GitHub.