{"record":{"id":"33594d213ffff840","repo":"xpzouying/xiaohongshu-mcp","slug":"error-33594d","errorCode":null,"errorMessage":"页面状态里没有未读数，可能未登录或页面结构已变化","messagePattern":"页面状态里没有未读数，可能未登录或页面结构已变化","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/notification.go","lineNumber":120,"sourceCode":"\tpage.MustNavigate(\"https://www.xiaohongshu.com/explore\").MustWaitLoad()\n\thumanize.Delay(ctx, humanize.AfterNavigate)\n\n\tif err := page.WaitStable(time.Second); err != nil {\n\t\tlogrus.Warnf(\"explore 页未稳定，继续读取未读数: %v\", err)\n\t}\n\n\tres, err := page.Eval(`() => {\n\t\tconst s = window.__INITIAL_STATE__;\n\t\tconst c = s && s.notification && s.notification.notificationCount;\n\t\treturn c ? JSON.stringify(c) : \"\";\n\t}`)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"读取未读数失败: %w\", err)\n\t}\n\n\traw := res.Value.String()\n\tif raw == \"\" {\n\t\treturn nil, fmt.Errorf(\"页面状态里没有未读数，可能未登录或页面结构已变化\")\n\t}\n\n\tvar count rawCount\n\tif err := json.Unmarshal([]byte(raw), &count); err != nil {\n\t\treturn nil, fmt.Errorf(\"解析未读数失败: %w\", err)\n\t}\n\treturn &NotificationCount{\n\t\tMentions:    count.Mentions,\n\t\tLikes:       count.Likes,\n\t\tConnections: count.Connections,\n\t\tUnread:      count.Unread,\n\t}, nil\n}\n\n// rawCount 是未读数在页面状态里的原始结构。\ntype rawCount struct {\n\tMentions    int `json:\"mentions\"`\n\tLikes       int `json:\"likes\"`","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/notification.go#L102-L138","documentation":"UnreadCount 的空值守卫：page.Eval 成功但返回空字符串，说明 window.__INITIAL_STATE__.notification.notificationCount 不存在——大概率是未登录（无通知数据注入）或小红书前端改了状态结构。","triggerScenarios":"Thrown at xiaohongshu/notification.go:120 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["先确认浏览器会话已登录小红书","检查页面状态结构是否变化并更新取值路径"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}