{"record":{"id":"8e3125e1e96bf1d7","repo":"jackwener/OpenCLI","slug":"not-logged-into-xiaohongshu-could-not-resolve-cur","errorCode":null,"errorMessage":"Not logged into Xiaohongshu (could not resolve current user id)","messagePattern":"Not logged into Xiaohongshu \\(could not resolve current user id\\)","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/xiaohongshu/collection-helpers.js","lineNumber":226,"sourceCode":"    if (Array.isArray(reqs) && reqs.length > 0)\n        bucket.push(...reqs);\n    return extractNotesFromResponses(bucket, fallbackUserId);\n}\n\nexport async function resolveXhsUserId(page, rawId) {\n    if (rawId)\n        return normalizeXhsUserId(String(rawId));\n    await page.goto('https://www.xiaohongshu.com/explore');\n    await page.wait(2);\n    await throwIfLoginWall(page);\n    const userId = unwrapBrowserResult(await page.evaluate(`() => {\n      const user = window.__INITIAL_STATE__?.user?.userInfo;\n      const info = user?._value ?? user ?? {};\n      return info.user_id || info.userId || info.userID || '';\n    }`));\n    const clean = toCleanString(userId);\n    if (!clean) {\n        throw new AuthRequiredError('www.xiaohongshu.com', 'Not logged into Xiaohongshu (could not resolve current user id)');\n    }\n    return clean;\n}\n\nexport async function extractNotesFromDom(page) {\n    const payload = unwrapBrowserResult(await page.evaluate(EXTRACT_COLLECTION_DOM_JS));\n    if (!Array.isArray(payload)) {\n        throw new CommandExecutionError('xiaohongshu collection DOM extraction returned malformed rows');\n    }\n    return payload.filter((item) => item?.id);\n}\n\nexport async function fetchXhsCollectionNotes(page, {\n    userId,\n    profileTab,\n    apiPattern,\n    limit,\n    emptyLabel,","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xiaohongshu/collection-helpers.js#L208-L244","documentation":"Thrown by resolveXhsUserId when the browser-side evaluation of window.__INITIAL_STATE__.user.userInfo (or _value) yields no user_id/userId/userID string. It means the XHS web session does not expose a logged-in user id, so collection scraping cannot proceed.","triggerScenarios":"page.evaluate returns an empty string after toCleanString because the user info object is missing, the state has not hydrated, or the visitor is not authenticated.","commonSituations":"Expired or absent login cookies, scraping a fresh incognito browser context, XHS changed the __INITIAL_STATE__ shape, or the profile page redirected to a guest view.","solutions":["Log into www.xiaohongshu.com in the browser profile/context used by the library (or supply cookies) and retry.","Verify window.__INITIAL_STATE__?.user?.userInfo resolves in the page console before running the command.","Check for XHS frontend changes and update the extraction script inside collection-helpers.js to the new state path.","Wrap the call in try/catch for AuthRequiredError and prompt the user to re-authenticate."],"exampleFix":"// before\nconst clean = toCleanString(userId);\nif (!clean) throw new AuthRequiredError('www.xiaohongshu.com', 'Not logged into Xiaohongshu ...');\n// after\nconst clean = toCleanString(userId);\nif (!clean) {\n  await promptLogin(page); // guide user through login, then re-resolve\n  userId = await page.evaluate(...);\n}","handlingStrategy":"try-catch","validationCode":"const userId = await page.evaluate('(() => { const u = window.__INITIAL_STATE__?.user?.userInfo; const i = u?._value ?? u ?? {}; return i.user_id || i.userId || i.userID || \"\"; })()');\nif (!userId) throw new Error('Pre-check: not logged into XHS');","typeGuard":"function hasXhsUser(state) {\n  const u = state?.user?.userInfo;\n  const i = u?._value ?? u ?? {};\n  return typeof (i.user_id || i.userId || i.userID) === 'string' && Boolean(i.user_id || i.userId || i.userID);\n}","tryCatchPattern":"try {\n  const userId = await resolveXhsUserId(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await promptManualLogin(e.domain);\n    return retry();\n  }\n  throw e;\n}","preventionTips":["Persist a logged-in browser profile (user data dir / cookies) between runs.","Check login state on the profile page before starting collection scraping.","Watch for XHS frontend changes to __INITIAL_STATE__ and update selectors.","Handle AuthRequiredError explicitly instead of letting it crash batch jobs."],"tags":["auth","scraping","browser-automation"],"backgroundTag":"not-authenticated","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}