{"record":{"id":"79adac906e5f309a","repo":"xpzouying/xiaohongshu-mcp","slug":"failed-to-navigate-to-profile-page-via-sidebar-w","errorCode":null,"errorMessage":"failed to navigate to profile page via sidebar: %w","messagePattern":"failed to navigate to profile page via sidebar: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/user_profile.go","lineNumber":156,"sourceCode":"}\n\nfunc makeUserProfileURL(userID, xsecToken string, tab ProfileTab) string {\n\turl := fmt.Sprintf(\"https://www.xiaohongshu.com/user/profile/%s?xsec_token=%s&xsec_source=pc_note\", userID, xsecToken)\n\tif tab != \"\" && tab != TabNotes {\n\t\turl += fmt.Sprintf(\"&tab=%s&subTab=note\", tab)\n\t}\n\treturn url\n}\n\nfunc (u *UserProfileAction) GetMyProfileViaSidebar(ctx context.Context, tab ProfileTab) (*UserProfileResponse, error) {\n\tpage := u.page.Context(ctx).Timeout(60 * time.Second) // 重设被 .Context 清掉的 deadline\n\n\t// 创建导航动作\n\tnavigate := NewNavigate(page)\n\n\t// 通过侧边栏导航到个人主页\n\tif err := navigate.ToProfilePage(ctx); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to navigate to profile page via sidebar: %w\", err)\n\t}\n\n\t// 等待页面加载完成并获取 __INITIAL_STATE__\n\tpage.MustWaitStable()\n\n\tif err := u.selectTab(ctx, page, tab); err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn u.extractUserProfileData(page, tab)\n}\n\n// selectTab 切到目标子 tab。「笔记」是默认 tab，无需点击。\nfunc (u *UserProfileAction) selectTab(ctx context.Context, page *rod.Page, tab ProfileTab) error {\n\tif tab == \"\" || tab == TabNotes {\n\t\treturn nil\n\t}\n","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/user_profile.go#L138-L174","documentation":"GetMyProfileViaSidebar wraps any failure from navigate.ToProfilePage — the sidebar-driven navigation to the logged-in user's profile page (xiaohongshu/user_profile.go:156). This library drives a real browser via go-rod, so navigation can fail if the sidebar element is missing, not clickable, or the target page never loads. The wrapped inner error from Navigate.ToProfilePage carries the specific cause.","triggerScenarios":"Calling GetMyProfileViaSidebar(ctx, tab) when the sidebar '我' (profile) entry cannot be found or clicked: not logged in, sidebar DOM changed, page stuck loading, or browser context cancelled/timed out.","commonSituations":"Expired or missing login session so the sidebar renders differently; XHS frontend markup update renaming sidebar selectors; slow network exceeding the 60s page timeout; ctx cancelled by caller.","solutions":["Inspect the wrapped cause (%w) to see whether it is element-not-found vs timeout vs context cancelled.","Re-login / refresh cookies so the sidebar renders with the profile entry.","Retry with a fresh page and a live context; check network stability.","If XHS changed its DOM, update the sidebar selectors in the Navigate action."],"exampleFix":"// before\nresp, err := action.GetMyProfileViaSidebar(ctx, xiaohongshu.TabNotes)\n// after\nif err := ensureLoggedIn(ctx, browser); err != nil {\n    return fmt.Errorf(\"login required before profile fetch: %w\", err)\n}\nresp, err := action.GetMyProfileViaSidebar(ctx, xiaohongshu.TabNotes)","handlingStrategy":"retry","validationCode":"if _, err := store.LoadCookies(); err != nil {\n    return fmt.Errorf(\"login required before GetMyProfileViaSidebar: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"resp, err := action.GetMyProfileViaSidebar(ctx, tab)\nif err != nil {\n    var navErr *NavigationError // or inspect errors.Unwrap chain\n    log.Printf(\"sidebar nav failed: %v\", err) // wrapped cause is in err chain\n    return fmt.Errorf(\"profile fetch failed: %w\", err)\n}","preventionTips":["Ensure a valid logged-in session (fresh cookies) before calling.","Pass a non-cancelled context with sufficient deadline.","Retry transient navigation failures with backoff.","Watch for XHS frontend updates that change sidebar markup."],"tags":["browser-automation","navigation","go-rod","xiaohongshu"],"backgroundTag":"sidebar-navigation-failed","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}