xpzouying/xiaohongshu-mcp · error
输入标题失败
Error message
输入标题失败
What it means
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.
Source
Thrown at xiaohongshu/publish.go:350
}
if currentCount >= expectedCount {
slog.Info("图片上传完成", "count", currentCount)
return nil
}
time.Sleep(checkInterval)
}
return errors.Errorf("第%d张图片上传超时(60s),请检查网络连接和图片大小", expectedCount)
}
func submitPublish(ctx context.Context, page *rod.Page, title, content string, tags []string, scheduleTime *time.Time, isOriginal bool, visibility string, products []string) error {
titleElem, err := page.Element("div.d-input input")
if err != nil {
return errors.Wrap(err, "查找标题输入框失败")
}
if err := humanize.Type(ctx, titleElem, title); err != nil {
return errors.Wrap(err, "输入标题失败")
}
humanize.Delay(ctx, humanize.AfterType)
if err := checkTitleMaxLength(page); err != nil {
return err
}
slog.Info("检查标题长度:通过")
humanize.Delay(ctx, humanize.AfterType)
contentElem, err := getContentElement(page, contentElemTimeout)
if err != nil {
return err
}
if err := humanize.Type(ctx, contentElem, content); err != nil {
return errors.Wrap(err, "输入正文失败")
}
if err := waitAndClickTitleInput(titleElem); err != nil {View on GitHub (pinned to 332d196854)
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
Example fix
// before
if err := humanize.Type(ctx, titleElem, title); err != nil {
return errors.Wrap(err, "输入标题失败")
}
// after
if err := humanize.Type(ctx, titleElem, title); err != nil {
return errors.Wrap(err, "输入标题失败") // 失败时截图排查遮挡/页面跳转
}
// 调用侧:对整体 Publish 做一次重试 Defensive patterns
Strategy: try-catch
Validate before calling
if strings.TrimSpace(title) == "" { return errors.New("标题不能为空") }
if len([]rune(title)) > 20 { return errors.New("标题超过小红书20字限制") } Try / catch
err := bot.Publish(ctx, post, images)
if err != nil && strings.Contains(err.Error(), "输入标题失败") {
// 重试一次; 仍失败则截图检查页面遮挡/会话
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/3a7f648f6ac25ea8.
Report an issue: GitHub.