xpzouying/xiaohongshu-mcp · error
failed to navigate to profile page via sidebar
Error message
failed to navigate to profile page via sidebar: %w
What it means
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.
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.
Example fix
// before
resp, err := action.GetMyProfileViaSidebar(ctx, xiaohongshu.TabNotes)
// after
if err := ensureLoggedIn(ctx, browser); err != nil {
return fmt.Errorf("login required before profile fetch: %w", err)
}
resp, err := action.GetMyProfileViaSidebar(ctx, xiaohongshu.TabNotes) Defensive patterns
Strategy: retry
Validate before calling
if _, err := store.LoadCookies(); err != nil {
return fmt.Errorf("login required before GetMyProfileViaSidebar: %w", err)
} Try / catch
resp, err := action.GetMyProfileViaSidebar(ctx, tab)
if err != nil {
var navErr *NavigationError // or inspect errors.Unwrap chain
log.Printf("sidebar nav failed: %v", err) // wrapped cause is in err chain
return fmt.Errorf("profile fetch failed: %w", err)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/79adac906e5f309a.
Report an issue: GitHub.
Appendix: source
Thrown at xiaohongshu/user_profile.go:156
}
func makeUserProfileURL(userID, xsecToken string, tab ProfileTab) string {
url := fmt.Sprintf("https://www.xiaohongshu.com/user/profile/%s?xsec_token=%s&xsec_source=pc_note", userID, xsecToken)
if tab != "" && tab != TabNotes {
url += fmt.Sprintf("&tab=%s&subTab=note", tab)
}
return url
}
func (u *UserProfileAction) GetMyProfileViaSidebar(ctx context.Context, tab ProfileTab) (*UserProfileResponse, error) {
page := u.page.Context(ctx).Timeout(60 * time.Second) // 重设被 .Context 清掉的 deadline
// 创建导航动作
navigate := NewNavigate(page)
// 通过侧边栏导航到个人主页
if err := navigate.ToProfilePage(ctx); err != nil {
return nil, fmt.Errorf("failed to navigate to profile page via sidebar: %w", err)
}
// 等待页面加载完成并获取 __INITIAL_STATE__
page.MustWaitStable()
if err := u.selectTab(ctx, page, tab); err != nil {
return nil, err
}
return u.extractUserProfileData(page, tab)
}
// selectTab 切到目标子 tab。「笔记」是默认 tab,无需点击。
func (u *UserProfileAction) selectTab(ctx context.Context, page *rod.Page, tab ProfileTab) error {
if tab == "" || tab == TabNotes {
return nil
}
View on GitHub (pinned to 332d196854)