xpzouying/xiaohongshu-mcp · error
输入正文失败
Error message
输入正文失败
What it means
After typing the title, submitPublish fetches the content (正文) editor via getContentElement and types the body text with humanize.Type. A failure during that typing is wrapped as '输入正文失败'. The content editor is a rich-text area, so failures usually come from the editor being stale, covered, or rendered differently than expected.
Source
Thrown at xiaohongshu/publish.go:366
}
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 {
return err
}
if err := inputTags(ctx, contentElem, tags); err != nil {
return err
}
humanize.Delay(ctx, humanize.AfterType)
if err := checkContentMaxLength(page); err != nil {
return err
}
slog.Info("检查正文长度:通过")
if scheduleTime != nil {
if err := setSchedulePublish(ctx, page, *scheduleTime); err != nil {
return errors.Wrap(err, "设置定时发布失败")View on GitHub (pinned to 332d196854)
Solutions
- Retry Publish once — rich-text editors often re-render and a fresh run succeeds
- Confirm content is non-empty and within the length limit (checkContentMaxLength runs after typing, but pre-validate yourself)
- Screenshot at failure to check for popups/suggestions covering the editor
- Increase content-element timeout passed to getContentElement if the editor loads slowly
- Keep browser/CDP session healthy; avoid concurrent operations on the same page during typing
Example fix
// before
if err := humanize.Type(ctx, contentElem, content); err != nil {
return errors.Wrap(err, "输入正文失败")
}
// after
if err := humanize.Type(ctx, contentElem, content); err != nil {
return errors.Wrap(err, "输入正文失败") // 建议调用侧重试一次并截图排查编辑器遮挡
} Defensive patterns
Strategy: try-catch
Validate before calling
if strings.TrimSpace(content) == "" { return errors.New("正文不能为空") }
if len([]rune(content)) > 1000 { return errors.New("正文过长, 请精简") } Try / catch
err := bot.Publish(ctx, post, images)
if err != nil && strings.Contains(err.Error(), "输入正文失败") {
// 重试一次; 仍失败则截图检查富文本编辑器状态
} Prevention
- Pre-validate content length against Xiaohongshu's limit
- Retry once — editors often re-render after title click
- Watch for editor suggestion popups intercepting keystrokes
- Keep the browser/CDP session stable during typing
When it happens
Trigger: humanize.Type(ctx, contentElem, content) erroring in submitPublish (xiaohongshu/publish.go:366), after getContentElement already succeeded.
Common situations: Rich-text editor re-rendered after clicking the title input (waitAndClickTitleInput) invalidating the element handle; empty/oversized content; an editor toolbar popup or suggestion dropdown intercepts keystrokes; very long content slows typing past internal timeouts; CDP disconnect mid-typing.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/0d2b0f497f607212.
Report an issue: GitHub.