xpzouying/xiaohongshu-mcp · error
按下方向键失败
Error message
按下方向键失败
What it means
This error wraps a failure when executing the ArrowDown key press (ka.Type(input.ArrowDown).Do()) inside inputTags' 20-iteration caret navigation loop. KeyActions() succeeded but dispatching the key event via CDP failed — usually a browser-side issue: page crashed, navigation interrupted, or input dispatch rejected.
Source
Thrown at xiaohongshu/publish.go:700
}
return findTextboxByPlaceholder(page)
}
func inputTags(ctx context.Context, contentElem *rod.Element, tags []string) error {
if len(tags) == 0 {
return nil
}
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)View on GitHub (pinned to 332d196854)
Solutions
- Retry the publish flow — transient input dispatch failures usually clear on a fresh run.
- Verify the page stays stable (no auto-navigation/modals) during tag input.
- Check browser health (memory, crash logs) if it recurs; restart the browser.
- Replace keyboard caret navigation with mouse/caret API (e.g. click at end of text) for robustness.
Example fix
// before
if err := ka.Type(input.ArrowDown).Do(); err != nil {
return errors.Wrap(err, "按下方向键失败")
}
// after
if err := ka.Type(input.ArrowDown).Do(); err != nil {
if isTransient(err) {
time.Sleep(500 * time.Millisecond)
continue // retry this key press
}
return errors.Wrap(err, "按下方向键失败")
} Defensive patterns
Strategy: retry
Validate before calling
// confirm the page is stable (same URL, no dialog) before keyboard input
if cur := page.Info().URL; cur != publishURL {
return fmt.Errorf("页面已跳转: %s", cur)
} Try / catch
err := publisher.Publish(ctx, opts)
if err != nil && strings.Contains(err.Error(), "按下方向键失败") {
// transient input dispatch failure: retry with backoff
time.Sleep(time.Second)
err = publisher.Publish(ctx, opts)
} Prevention
- Suppress site popups/dialogs that can steal key events
- Add small delays between key dispatches under load
- Verify browser/renderer stability; restart if crashes recur
- Prefer direct caret APIs over long arrow-key sequences
When it happens
Trigger: inputTags (called by submitPublish/submitPublishVideo) is stepping the caret down with ArrowDown; the Do() call on the key action returns an error from the browser (page navigating/crashed, input domain failure).
Common situations: Tab navigated away mid-loop; browser under heavy load dropping input events; editor captured key events and triggered navigation; CDP connection instability.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/664846e716e8d367.
Report an issue: GitHub.