xpzouying/xiaohongshu-mcp · error
读取未读数失败: %w
Error message
读取未读数失败: %w
What it means
UnreadCount 在 explore 页执行 JS 读取 window.__INITIAL_STATE__.notification.notificationCount 时 page.Eval 失败:页面导航未完成、JS 执行上下文被销毁,或页面结构变化导致脚本异常。
Source
Thrown at xiaohongshu/notification.go:115
// UnreadCount 读取三个分区的未读数。
func (n *NotificationAction) UnreadCount(ctx context.Context) (*NotificationCount, error) {
page := n.page.Timeout(60 * time.Second)
page.MustNavigate("https://www.xiaohongshu.com/explore").MustWaitLoad()
humanize.Delay(ctx, humanize.AfterNavigate)
if err := page.WaitStable(time.Second); err != nil {
logrus.Warnf("explore 页未稳定,继续读取未读数: %v", err)
}
res, err := page.Eval(`() => {
const s = window.__INITIAL_STATE__;
const c = s && s.notification && s.notification.notificationCount;
return c ? JSON.stringify(c) : "";
}`)
if err != nil {
return nil, fmt.Errorf("读取未读数失败: %w", err)
}
raw := res.Value.String()
if raw == "" {
return nil, fmt.Errorf("页面状态里没有未读数,可能未登录或页面结构已变化")
}
var count rawCount
if err := json.Unmarshal([]byte(raw), &count); err != nil {
return nil, fmt.Errorf("解析未读数失败: %w", err)
}
return &NotificationCount{
Mentions: count.Mentions,
Likes: count.Likes,
Connections: count.Connections,
Unread: count.Unread,
}, nil
}View on GitHub (pinned to 332d196854)
Solutions
- 重试一次以排除页面加载抖动
- 确认登录态有效
- 核对 __INITIAL_STATE__ 路径是否仍存在
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at xiaohongshu/notification.go:115 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/c1a10a68331f70bc.
Report an issue: GitHub.