{"record":{"id":"60dfd06f12672282","repo":"jackwener/OpenCLI","slug":"xiaohongshu-collection-page-requires-login-re-log","errorCode":null,"errorMessage":"Xiaohongshu collection page requires login; re-login to xiaohongshu.com and retry.","messagePattern":"Xiaohongshu collection page requires login; re-login to xiaohongshu\\.com and retry\\.","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/collection-helpers.js","lineNumber":182,"sourceCode":"    const userStore = window.__INITIAL_STATE__?.user;\n    const loggedInVal = userStore ? (userStore.loggedIn?._value ?? userStore.loggedIn) : undefined;\n    const bodyText = document.body?.innerText || '';\n    return Boolean(pathName.indexOf('/login') === 0 || loggedInVal === false || /登录后|请先登录|登录后查看/.test(bodyText));\n  })()\n`;\n\nconst CURRENT_LOCATION_JS = `\n  (() => ({\n    href: location.href,\n    hostname: location.hostname,\n    pathname: location.pathname,\n  }))()\n`;\n\nasync function throwIfLoginWall(page) {\n    const payload = unwrapBrowserResult(await page.evaluate(LOGIN_WALL_JS));\n    if (payload === true) {\n        throw new AuthRequiredError('www.xiaohongshu.com', 'Xiaohongshu collection page requires login; re-login to xiaohongshu.com and retry.');\n    }\n}\n\nexport async function assertOnCollectionProfile(page, userId) {\n    await throwIfLoginWall(page);\n    const payload = unwrapBrowserResult(await page.evaluate(CURRENT_LOCATION_JS));\n    if (!isObject(payload)) {\n        throw new CommandExecutionError('xiaohongshu collection page returned malformed location');\n    }\n    const hostname = toCleanString(payload.hostname).toLowerCase();\n    const pathname = toCleanString(payload.pathname);\n    if (hostname === 'www.xiaohongshu.com' && pathname === '/login') {\n        throw new AuthRequiredError('xiaohongshu collection page requires login');\n    }\n    const expectedPath = `/user/profile/${toCleanString(userId)}`;\n    if (hostname !== 'www.xiaohongshu.com' || pathname !== expectedPath) {\n        throw new CommandExecutionError(`xiaohongshu collection landed on unexpected page: ${toCleanString(payload.href) || `${hostname}${pathname}`}`);\n    }","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/collection-helpers.js#L164-L200","documentation":"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.","triggerScenarios":"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.","commonSituations":"Session cookies expired (web sessions for xiaohongshu are short-lived); fresh browser profile never logged in; xiaohongshu forced re-login after risk-control flagging.","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"],"exampleFix":"// before\nconst notes = await fetchXhsCollectionNotes(page, userId); // AuthRequiredError\n// after\nif (!(await isLoggedInToXhs(page))) {\n  await performXhsLogin(page); // scripted login or prompt user\n}\nconst notes = await fetchXhsCollectionNotes(page, userId);","handlingStrategy":"retry","validationCode":"const loginWallDetected = (page) => page.evaluate(() => !!document.querySelector('.login-container, .sign-in-container, [class*=\"login\"]'));","typeGuard":"const looksLoggedIn = (payload) => payload !== true;","tryCatchPattern":"try { notes = await fetchXhsCollectionNotes(page, userId); } catch (e) { if (e instanceof AuthRequiredError) { await performXhsLogin(page); notes = await fetchXhsCollectionNotes(page, userId); } else throw e; }","preventionTips":["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"],"tags":["auth","login-required","scraping","auth-required-error"],"backgroundTag":"login-required","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}