{"record":{"id":"c76f0f61cadd56d4","repo":"xpzouying/xiaohongshu-mcp","slug":"error-c76f0f","errorCode":null,"errorMessage":"点击发布按钮失败","messagePattern":"点击发布按钮失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":446,"sourceCode":"}\n\ntype publishButton struct {\n\telem     *rod.Element\n\tisWidget bool\n}\n\nfunc clickPublishButton(page *rod.Page) error {\n\tbtn, err := waitForPublishButtonClickable(page, 15*time.Second)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif btn.isWidget {\n\t\treturn clickPublishWidget(page, btn.elem)\n\t}\n\n\tif err := humanize.Click(btn.elem); err != nil {\n\t\treturn errors.Wrap(err, \"点击发布按钮失败\")\n\t}\n\treturn nil\n}\n\n// waitForPublishButtonClickable 等待新版 xhs-publish-btn 或旧版 button.bg-red 可点击。\nfunc waitForPublishButtonClickable(page *rod.Page, maxWait time.Duration) (*publishButton, error) {\n\tinterval := 1 * time.Second\n\tstart := time.Now()\n\tvar lastDisabledReason string\n\n\tslog.Info(\"开始等待发布按钮可点击\")\n\n\tfor time.Since(start) < maxWait {\n\t\tbtn, disabledReason, err := findPublishButton(page)\n\t\tif err != nil {\n\t\t\tslog.Warn(\"查找发布按钮失败，继续等待\", \"error\", err)\n\t\t\ttime.Sleep(interval)\n\t\t\tcontinue","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L428-L464","documentation":"Raised in clickPublishButton when humanize.Click fails to physically click the located publish button element. The button was found and considered clickable, but the simulated human click (element interaction) errored.","triggerScenarios":"The button element becomes detached/stale between finding it and clicking; the element is covered by an overlay or modal; the browser page was closed or navigated; rod's click action times out.","commonSituations":"A toast, dialog, or login prompt covers the publish button; SPA re-render replaced the element node mid-flow; browser context killed by timeout.","solutions":["Retry the publish; stale-element races usually resolve on a fresh run","Ensure no overlays/dialogs block the button before publishing (e.g. complete any captcha first)","Check the browser/page is alive and the publish page fully loaded","Update the library if Xiaohongshu renders new overlays on the publish page"],"exampleFix":"// before\n// click fails because a modal overlays the button\nerr := xhs.Publish(...) // 设置可见范围失败/点击发布按钮失败\n// after\n// dismiss dialogs first, then publish\npage.MustDismissDialog()\nerr := xhs.Publish(...)","handlingStrategy":"retry","validationCode":"// 发布前确认页面无弹窗遮挡\nif info, err := page.Info(); err != nil || !strings.Contains(info.URL, \"/publish/publish\") {\n    return errors.New(\"发布页未就绪\")\n}","typeGuard":null,"tryCatchPattern":"err := xhs.Publish(...)\nif err != nil && strings.Contains(err.Error(), \"点击发布按钮失败\") {\n    time.Sleep(2 * time.Second)\n    err = xhs.Publish(...) // 重试一次\n}","preventionTips":["Dismiss dialogs/toasts/captchas before publishing","Keep the browser tab alive during the whole publish flow","Retry stale-element clicks once with a short backoff","Avoid navigating away mid-flow"],"tags":["browser-automation","rod","click"],"backgroundTag":"element-click-failed","analyzedSha":"332d196854a9eac0d2b8c2c0e3d0cc43139d724c","analyzedAt":"2026-09-05T22:22:55.988Z","contentChangedAt":"2026-09-05T22:22:55.988Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}