{"record":{"id":"3a7f648f6ac25ea8","repo":"xpzouying/xiaohongshu-mcp","slug":"error-3a7f64","errorCode":null,"errorMessage":"输入标题失败","messagePattern":"输入标题失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":350,"sourceCode":"\t\t}\n\t\tif currentCount >= expectedCount {\n\t\t\tslog.Info(\"图片上传完成\", \"count\", currentCount)\n\t\t\treturn nil\n\t\t}\n\n\t\ttime.Sleep(checkInterval)\n\t}\n\n\treturn errors.Errorf(\"第%d张图片上传超时(60s)，请检查网络连接和图片大小\", expectedCount)\n}\n\nfunc submitPublish(ctx context.Context, page *rod.Page, title, content string, tags []string, scheduleTime *time.Time, isOriginal bool, visibility string, products []string) error {\n\ttitleElem, err := page.Element(\"div.d-input input\")\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"查找标题输入框失败\")\n\t}\n\tif err := humanize.Type(ctx, titleElem, title); err != nil {\n\t\treturn errors.Wrap(err, \"输入标题失败\")\n\t}\n\n\thumanize.Delay(ctx, humanize.AfterType)\n\tif err := checkTitleMaxLength(page); err != nil {\n\t\treturn err\n\t}\n\tslog.Info(\"检查标题长度：通过\")\n\n\thumanize.Delay(ctx, humanize.AfterType)\n\n\tcontentElem, err := getContentElement(page, contentElemTimeout)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif err := humanize.Type(ctx, contentElem, content); err != nil {\n\t\treturn errors.Wrap(err, \"输入正文失败\")\n\t}\n\tif err := waitAndClickTitleInput(titleElem); err != nil {","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L332-L368","documentation":"After finding the title input, submitPublish calls humanize.Type to simulate human typing of the title. If typing fails (element detached, page navigated, CDP error, input not editable), the error is wrapped as '输入标题失败'. The element was found, so this is an interaction failure rather than a locator failure.","triggerScenarios":"humanize.Type(ctx, titleElem, title) returning a non-nil error in submitPublish (xiaohongshu/publish.go:350) — element became stale, page redirected, or keyboard input was blocked.","commonSituations":"Page navigated/re-rendered between finding the element and typing; an overlay/modal intercepts input; empty title passed in triggers validation elsewhere; browser or CDP connection dropped mid-run; site JS disabled the input until some precondition (e.g. images uploaded).","solutions":["Retry the publish flow — transient DOM re-renders often resolve on a fresh attempt","Confirm the title string is non-empty and within Xiaohongshu's length limit","Screenshot the page at failure time to check for overlays/modals blocking the input","Ensure images finished uploading before the form is interacted with (page state precondition)","Check CDP/browser stability (page not closed, browser not crashed) and rod/humanize versions"],"exampleFix":"// before\nif err := humanize.Type(ctx, titleElem, title); err != nil {\n    return errors.Wrap(err, \"输入标题失败\")\n}\n// after\nif err := humanize.Type(ctx, titleElem, title); err != nil {\n    return errors.Wrap(err, \"输入标题失败\") // 失败时截图排查遮挡/页面跳转\n}\n// 调用侧：对整体 Publish 做一次重试","handlingStrategy":"try-catch","validationCode":"if strings.TrimSpace(title) == \"\" { return errors.New(\"标题不能为空\") }\nif len([]rune(title)) > 20 { return errors.New(\"标题超过小红书20字限制\") }","typeGuard":null,"tryCatchPattern":"err := bot.Publish(ctx, post, images)\nif err != nil && strings.Contains(err.Error(), \"输入标题失败\") {\n    // 重试一次; 仍失败则截图检查页面遮挡/会话\n}","preventionTips":["Pre-validate title length (Xiaohongshu caps around 20 chars) and non-emptiness","Retry the flow once on transient typing errors","Avoid concurrent page operations during publish","Check for site popups/overlays that steal focus"],"tags":["humanize","typing","browser-automation","element-stale"],"backgroundTag":"element-interaction-failed","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"}