{"record":{"id":"c1a10a68331f70bc","repo":"xpzouying/xiaohongshu-mcp","slug":"w-c1a10a","errorCode":null,"errorMessage":"读取未读数失败: %w","messagePattern":"读取未读数失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/notification.go","lineNumber":115,"sourceCode":"\n// UnreadCount 读取三个分区的未读数。\nfunc (n *NotificationAction) UnreadCount(ctx context.Context) (*NotificationCount, error) {\n\tpage := n.page.Timeout(60 * time.Second)\n\n\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}","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/notification.go#L97-L133","documentation":"UnreadCount 在 explore 页执行 JS 读取 window.__INITIAL_STATE__.notification.notificationCount 时 page.Eval 失败：页面导航未完成、JS 执行上下文被销毁，或页面结构变化导致脚本异常。","triggerScenarios":"Thrown at xiaohongshu/notification.go:115 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["重试一次以排除页面加载抖动","确认登录态有效","核对 __INITIAL_STATE__ 路径是否仍存在"],"exampleFix":null,"handlingStrategy":"retry","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-14T05:17:10.506Z"}