xpzouying/xiaohongshu-mcp · error

页面状态里没有未读数,可能未登录或页面结构已变化

Error message

页面状态里没有未读数,可能未登录或页面结构已变化

What it means

UnreadCount 的空值守卫:page.Eval 成功但返回空字符串,说明 window.__INITIAL_STATE__.notification.notificationCount 不存在——大概率是未登录(无通知数据注入)或小红书前端改了状态结构。

Source

Thrown at xiaohongshu/notification.go:120

	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
}

// rawCount 是未读数在页面状态里的原始结构。
type rawCount struct {
	Mentions    int `json:"mentions"`
	Likes       int `json:"likes"`

View on GitHub (pinned to 332d196854)

Solutions

  1. 先确认浏览器会话已登录小红书
  2. 检查页面状态结构是否变化并更新取值路径
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at xiaohongshu/notification.go:120 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/33594d213ffff840. Report an issue: GitHub.