xpzouying/xiaohongshu-mcp · error
读取通知列表失败: %w
Error message
读取通知列表失败: %w
What it means
readTab 执行 page.Eval 从 window.__INITIAL_STATE__.notification.notificationMap 读取分区数据时脚本执行失败:页面上下文变化、导航中或 JS 异常。数据尚未注入的情况走另一个空值分支。
Source
Thrown at xiaohongshu/notification.go:293
const itemTypeNote = "note_info"
// from 返回发起这条通知的用户。
func (r rawNotification) from() rawUser {
if r.UserInfo.UserID != "" || r.UserInfo.Nickname != "" {
return r.UserInfo
}
return r.User
}
// readTab 读取指定分区的原始数据,字段映射由结构体承担。
func (n *NotificationAction) readTab(page *rod.Page, tab NotificationTab) (*notificationPayload, error) {
res, err := page.Eval(`(tab) => {
const s = window.__INITIAL_STATE__;
const m = s && s.notification && s.notification.notificationMap;
return m && m[tab] ? JSON.stringify(m[tab]) : "";
}`, string(tab))
if err != nil {
return nil, fmt.Errorf("读取通知列表失败: %w", err)
}
raw := res.Value.String()
if raw == "" {
return nil, fmt.Errorf("页面状态里没有分区 %s,可能未登录或页面结构已变化", tab)
}
var payload notificationPayload
if err := json.Unmarshal([]byte(raw), &payload); err != nil {
return nil, fmt.Errorf("解析通知列表失败: %w", err)
}
return &payload, nil
}
// visible 判断一条通知的内容是否仍然正常可见。
func (r rawNotification) visible() bool {
if r.Comment.ID != "" && r.Comment.Illegal.Status != "" && r.Comment.Illegal.Status != statusNormal {
return falseView on GitHub (pinned to 332d196854)
Solutions
- 确认调用前页面已加载完成(MustWaitLoad / WaitStable 后再调用)
- 打印 %w 展开的原始 rod 错误,判断是 Eval JS 报错还是连接问题
- 若为连接/超时问题,重建浏览器或 page 后重试
- 若页面结构变化导致 JS 抛错,更新 readTab 里的注入脚本选择器
Example fix
// before
res, err := page.Eval(`(tab) => { ... }`, string(tab))
if err != nil { return nil, fmt.Errorf("读取通知列表失败: %w", err) }
// after
page = page.Timeout(30 * time.Second)
page.MustWaitLoad()
res, err := page.Eval(`(tab) => { ... }`, string(tab))
if err != nil {
log.Printf("readTab eval failed: %v", err)
return nil, fmt.Errorf("读取通知列表失败: %w", err)
} Defensive patterns
Strategy: retry
Validate before calling
// 调用前确认浏览器与页面可用
if page == nil || browser == nil { return errors.New("browser/page not initialized") }
_ = page.Timeout(30 * time.Second).MustNavigate("https://www.xiaohongshu.com/notification").MustWaitLoad() Try / catch
items, err := n.List(ctx)
var wrapped *fmt.WrapError
if errors.As(err, &wrapped) && strings.Contains(err.Error(), "读取通知列表失败") {
// 重建 page 后重试
page = browser.MustPage(notificationURL)
items, err = n.List(ctx)
} Prevention
- 每次调用前确保页面已 MustWaitLoad 且未被导航走
- 为 page 设置合理 Timeout,避免默认立即失败
- 复用浏览器实例时检查 tab 有效性
- 关注小红书前端改版,及时更新注入脚本
When it happens
Trigger: 调用 NotificationAction.List / Reply / locate 等最终走 readTab 的接口时,page.Eval 返回 err:页面被导航走、浏览器 tab 已关闭、JS 在 __INITIAL_STATE__ 未定义前抛错、rod 连接中断。
Common situations: 页面还没渲染完就调用接口;浏览器实例被复用但 tab 已被关闭;小红书前端改版导致注入脚本抛异常;网络抖动导致 CDP 连接失败。
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/a5311cf6f5a4392d.
Report an issue: GitHub.