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

  1. Log in to www.xiaohongshu.com in the automation browser and retry
  2. Re-run your browser login/refresh-session helper before fetching
  3. Persist cookies so sessions survive across runs
  4. 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

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


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/60dfd06f12672282. Report an issue: GitHub.