{"record":{"id":"664846e716e8d367","repo":"xpzouying/xiaohongshu-mcp","slug":"error-664846","errorCode":null,"errorMessage":"按下方向键失败","messagePattern":"按下方向键失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":700,"sourceCode":"\t}\n\n\treturn findTextboxByPlaceholder(page)\n}\n\nfunc inputTags(ctx context.Context, contentElem *rod.Element, tags []string) error {\n\tif len(tags) == 0 {\n\t\treturn nil\n\t}\n\n\ttime.Sleep(1 * time.Second)\n\n\tfor i := 0; i < 20; i++ {\n\t\tka, err := contentElem.KeyActions()\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"创建键盘操作失败\")\n\t\t}\n\t\tif err := ka.Type(input.ArrowDown).Do(); err != nil {\n\t\t\treturn errors.Wrap(err, \"按下方向键失败\")\n\t\t}\n\t\ttime.Sleep(10 * time.Millisecond)\n\t}\n\n\tka, err := contentElem.KeyActions()\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"创建键盘操作失败\")\n\t}\n\tif err := ka.Press(input.Enter).Press(input.Enter).Do(); err != nil {\n\t\treturn errors.Wrap(err, \"按下回车键失败\")\n\t}\n\n\ttime.Sleep(1 * time.Second)\n\n\tfor _, tag := range tags {\n\t\ttag = strings.TrimLeft(tag, \"#\")\n\t\tif err := inputTag(ctx, contentElem, tag); err != nil {\n\t\t\treturn errors.Wrapf(err, \"输入标签[%s]失败\", tag)","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L682-L718","documentation":"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.","triggerScenarios":"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).","commonSituations":"Tab navigated away mid-loop; browser under heavy load dropping input events; editor captured key events and triggered navigation; CDP connection instability.","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."],"exampleFix":"// before\nif err := ka.Type(input.ArrowDown).Do(); err != nil {\n    return errors.Wrap(err, \"按下方向键失败\")\n}\n// after\nif err := ka.Type(input.ArrowDown).Do(); err != nil {\n    if isTransient(err) {\n        time.Sleep(500 * time.Millisecond)\n        continue // retry this key press\n    }\n    return errors.Wrap(err, \"按下方向键失败\")\n}","handlingStrategy":"retry","validationCode":"// confirm the page is stable (same URL, no dialog) before keyboard input\nif cur := page.Info().URL; cur != publishURL {\n    return fmt.Errorf(\"页面已跳转: %s\", cur)\n}","typeGuard":null,"tryCatchPattern":"err := publisher.Publish(ctx, opts)\nif err != nil && strings.Contains(err.Error(), \"按下方向键失败\") {\n    // transient input dispatch failure: retry with backoff\n    time.Sleep(time.Second)\n    err = publisher.Publish(ctx, opts)\n}","preventionTips":["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"],"tags":["keyboard-input","cdp","browser-automation","xiaohongshu"],"backgroundTag":"keyboard-event-dispatch-failed","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}