xpzouying/xiaohongshu-mcp · error
按下回车键失败
Error message
按下回车键失败
What it means
This error wraps a failure to execute the double-Enter key press (ka.Press(input.Enter).Press(input.Enter).Do()) in inputTags, which inserts newlines before hashtag input. The KeyActions chain was created but dispatching the Enter keys to the browser failed — a CDP input error typically caused by page instability.
Source
Thrown at xiaohongshu/publish.go:710
time.Sleep(1 * time.Second)
for i := 0; i < 20; i++ {
ka, err := contentElem.KeyActions()
if err != nil {
return errors.Wrap(err, "创建键盘操作失败")
}
if err := ka.Type(input.ArrowDown).Do(); err != nil {
return errors.Wrap(err, "按下方向键失败")
}
time.Sleep(10 * time.Millisecond)
}
ka, err := contentElem.KeyActions()
if err != nil {
return errors.Wrap(err, "创建键盘操作失败")
}
if err := ka.Press(input.Enter).Press(input.Enter).Do(); err != nil {
return errors.Wrap(err, "按下回车键失败")
}
time.Sleep(1 * time.Second)
for _, tag := range tags {
tag = strings.TrimLeft(tag, "#")
if err := inputTag(ctx, contentElem, tag); err != nil {
return errors.Wrapf(err, "输入标签[%s]失败", tag)
}
}
return nil
}
func inputTag(ctx context.Context, contentElem *rod.Element, tag string) error {
// 输入 # 触发话题联想
if err := humanize.Type(ctx, contentElem, "#"); err != nil {
return errors.Wrap(err, "输入#失败")
}View on GitHub (pinned to 332d196854)
Solutions
- Retry the publish flow from the start; input dispatch failures are often transient.
- Check the page for popups/modals that intercept Enter and dismiss them before publishing.
- Verify browser/connection stability; restart browser if crashes recur.
- Use the element's input/keyboard API for a newline instead of a chained double Press if the issue persists.
Example fix
// before
if err := ka.Press(input.Enter).Press(input.Enter).Do(); err != nil {
return errors.Wrap(err, "按下回车键失败")
}
// after
if err := ka.Press(input.Enter).Do(); err != nil {
return errors.Wrap(err, "按下回车键失败")
}
time.Sleep(50 * time.Millisecond)
if err := ka.Press(input.Enter).Do(); err != nil {
return errors.Wrap(err, "按下回车键失败")
} Defensive patterns
Strategy: retry
Validate before calling
// verify the page is interactive and no modal blocks input
if has, _, _ := page.Has(`div.modal, .dialog`); has {
return errors.New("存在弹窗,先关闭再输入")
} Try / catch
err := publisher.Publish(ctx, opts)
if err != nil && strings.Contains(err.Error(), "按下回车键失败") {
// transient CDP input failure: retry once
time.Sleep(time.Second)
err = publisher.Publish(ctx, opts)
} Prevention
- Dismiss popups before the keyboard sequence
- Press keys one at a time instead of chained presses
- Watch CDP connection stability on long flows
- Avoid triggering site shortcuts with Enter
When it happens
Trigger: inputTags (via submitPublish/submitPublishVideo) attempts ka.Press(input.Enter).Press(input.Enter).Do() and the browser returns an error — page navigating, crashed renderer, or dropped CDP connection.
Common situations: Site opened a dialog or navigated on Enter; browser under load; connection to the browser dropped mid-sequence; editor state changed making the input target invalid.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/449b2ee4ae0f38b1.
Report an issue: GitHub.