xpzouying/xiaohongshu-mcp · error

滚动新版发布按钮到可视区域失败

Error message

滚动新版发布按钮到可视区域失败

What it means

clickPublishWidget wraps the error returned by rod's Element.ScrollIntoView for the new-version (web component `xhs-publish-btn`) publish button. ScrollIntoView is a CDP DOM.scrollIntoViewIfNeeded call; it fails when the element is detached from the DOM or the browser connection is broken. The library cannot click the button unless it is in the viewport, so it aborts the click.

Source

Thrown at xiaohongshu/publish.go:547

		} else if ariaDisabled != nil && *ariaDisabled == "true" {
			return &publishButton{elem: oldButton}, "旧版发布按钮 aria-disabled=true", nil
		}

		if cls, err := oldButton.Attribute("class"); err != nil {
			return nil, "", errors.Wrap(err, "读取旧版发布按钮 class 属性失败")
		} else if cls != nil && hasExactClass(*cls, "disabled") {
			return &publishButton{elem: oldButton}, "旧版发布按钮包含 disabled class", nil
		}

		return &publishButton{elem: oldButton}, "", nil
	}

	return nil, "", nil
}

func clickPublishWidget(page *rod.Page, widget *rod.Element) error {
	if err := widget.ScrollIntoView(); err != nil {
		return errors.Wrap(err, "滚动新版发布按钮到可视区域失败")
	}
	time.Sleep(200 * time.Millisecond)

	shape, err := widget.Shape()
	if err != nil {
		return errors.Wrap(err, "获取新版发布按钮位置失败")
	}
	if len(shape.Quads) == 0 {
		return errors.New("获取新版发布按钮位置失败: 无可点击区域")
	}

	quad := shape.Quads[0]
	minX, maxX := quad[0], quad[0]
	minY, maxY := quad[1], quad[1]
	for i := 0; i < quad.Len(); i++ {
		x := quad[i*2]
		y := quad[i*2+1]
		if x < minX {

View on GitHub (pinned to 332d196854)

Solutions

  1. Re-run the find + click flow so a fresh element handle is obtained for the current DOM
  2. Wait for page stability (page.WaitStable / WaitDOMStable) before clicking, especially after file upload or dialog switches
  3. Confirm the rod page/browser is still connected; re-launch or re-open the page if the connection died
  4. If the widget is inside a custom element shadow DOM, ensure the custom element is registered (wait for the page's JS) before scrolling

Example fix

// before
if err := clickPublishButton(page); err != nil { return err }
// after
_ = page.WaitStable(300 * time.Millisecond)
if err := clickPublishButton(page); err != nil {
    _ = page.WaitStable(time.Second)
    return clickPublishButton(page)
}
Defensive patterns

Strategy: retry

Validate before calling

if err := page.WaitStable(300 * time.Millisecond); err != nil { return err }
widgets, err := page.Elements("xhs-publish-btn")
if err != nil || len(widgets) == 0 { return errors.New("新版发布按钮不存在") }
if !isElementVisible(widgets[0]) { return errors.New("新版发布按钮不可见") }

Type guard

func clickable(widget *rod.Element) bool {
    if widget == nil { return false }
    if !isElementVisible(widget) { return false }
    shape, err := widget.Shape()
    return err == nil && len(shape.Quads) > 0
}

Try / catch

err := clickPublishButton(page)
if err != nil && strings.Contains(err.Error(), "滚动新版发布按钮到可视区域失败") {
    time.Sleep(500 * time.Millisecond)
    err = clickPublishButton(page)
}

Prevention

When it happens

Trigger: Calling clickPublishButton while the new publish widget gets unmounted/re-created by the page; page navigated away between findPublishButton and the click; closed tab or dropped CDP connection.

Common situations: Uploading files changes the publish page state and re-renders the widget; clicking right after page load before hydration completes; automation running long after the browser window was closed.

Related errors


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