xpzouying/xiaohongshu-mcp · error
获取新版发布按钮位置失败: 无可点击区域
Error message
获取新版发布按钮位置失败: 无可点击区域
What it means
clickPublishWidget resolves the click coordinates of the new-version publish button (custom element `xhs-publish-btn`) from its rod Shape(). If Shape() succeeds but shape.Quads is empty, there is no clickable geometry to compute a click point, so this error is thrown. This usually means the element exists in the DOM but is not rendered (zero size, display:none, or inside a collapsed container).
Source
Thrown at xiaohongshu/publish.go:556
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 {
minX = x
}
if x > maxX {
maxX = x
}
if y < minY {
minY = y
}
if y > maxY {View on GitHub (pinned to 332d196854)
Solutions
- Wait for the element to be visible/stable (WaitVisible or WaitStable) before calling clickPublishWidget
- Retry the click once after a short sleep — transient layout races often resolve
- Fall back to the legacy publish-button selector path if the new-version widget renders empty
- Ensure a reasonable viewport size in headless mode (e.g. 1280x800) so all elements lay out
Example fix
// before
if len(shape.Quads) == 0 {
return errors.New("获取新版发布按钮位置失败: 无可点击区域")
}
// after
if len(shape.Quads) == 0 {
_ = widget.WaitStable(300 * time.Millisecond) // then retry Shape() once
shape, err = widget.Shape()
if err != nil || len(shape.Quads) == 0 {
return errors.New("获取新版发布按钮位置失败: 无可点击区域")
}
} Defensive patterns
Strategy: retry
Try / catch
if err := clickPublishButton(page); err != nil {
if strings.Contains(err.Error(), "无可点击区域") {
time.Sleep(1 * time.Second)
return clickPublishButton(page) // 布局稳定后重试
}
return err
} Prevention
- Wait for the button to be visible/stable before resolving its Shape()
- Use a normal desktop viewport (e.g. 1280x800) in headless mode
- Retry once on geometry errors — they are usually transient render races
When it happens
Trigger: clickPublishButton → clickPublishWidget calls widget.Shape(); quads list is empty because the custom element has no layout box — page not fully rendered, element hidden by CSS, or element detached/replaced right before Shape().
Common situations: Publish page still animating/rendering when clicked; XHS serving a variant where the button is nested such that the outer custom element has no box; headless viewport too small causing the element to not lay out; race where the page re-renders between finding and shaping the element.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/4777cc5699403cf6.
Report an issue: GitHub.