xpzouying/xiaohongshu-mcp · error

点击发布按钮失败

Error message

点击发布按钮失败

What it means

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.

Source

Thrown at xiaohongshu/publish.go:446

}

type publishButton struct {
	elem     *rod.Element
	isWidget bool
}

func clickPublishButton(page *rod.Page) error {
	btn, err := waitForPublishButtonClickable(page, 15*time.Second)
	if err != nil {
		return err
	}

	if btn.isWidget {
		return clickPublishWidget(page, btn.elem)
	}

	if err := humanize.Click(btn.elem); err != nil {
		return errors.Wrap(err, "点击发布按钮失败")
	}
	return nil
}

// waitForPublishButtonClickable 等待新版 xhs-publish-btn 或旧版 button.bg-red 可点击。
func waitForPublishButtonClickable(page *rod.Page, maxWait time.Duration) (*publishButton, error) {
	interval := 1 * time.Second
	start := time.Now()
	var lastDisabledReason string

	slog.Info("开始等待发布按钮可点击")

	for time.Since(start) < maxWait {
		btn, disabledReason, err := findPublishButton(page)
		if err != nil {
			slog.Warn("查找发布按钮失败,继续等待", "error", err)
			time.Sleep(interval)
			continue

View on GitHub (pinned to 332d196854)

Solutions

  1. Retry the publish; stale-element races usually resolve on a fresh run
  2. Ensure no overlays/dialogs block the button before publishing (e.g. complete any captcha first)
  3. Check the browser/page is alive and the publish page fully loaded
  4. Update the library if Xiaohongshu renders new overlays on the publish page

Example fix

// before
// click fails because a modal overlays the button
err := xhs.Publish(...) // 设置可见范围失败/点击发布按钮失败
// after
// dismiss dialogs first, then publish
page.MustDismissDialog()
err := xhs.Publish(...)
Defensive patterns

Strategy: retry

Validate before calling

// 发布前确认页面无弹窗遮挡
if info, err := page.Info(); err != nil || !strings.Contains(info.URL, "/publish/publish") {
    return errors.New("发布页未就绪")
}

Try / catch

err := xhs.Publish(...)
if err != nil && strings.Contains(err.Error(), "点击发布按钮失败") {
    time.Sleep(2 * time.Second)
    err = xhs.Publish(...) // 重试一次
}

Prevention

When it happens

Trigger: 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.

Common situations: A toast, dialog, or login prompt covers the publish button; SPA re-render replaced the element node mid-flow; browser context killed by timeout.

Related errors


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/c76f0f61cadd56d4. Report an issue: GitHub.