{"record":{"id":"5e52009ebfa247ba","repo":"xpzouying/xiaohongshu-mcp","slug":"error-5e5200","errorCode":null,"errorMessage":"获取新版发布按钮位置失败","messagePattern":"获取新版发布按钮位置失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"xiaohongshu/publish.go","lineNumber":553,"sourceCode":"\t\t} else if cls != nil && hasExactClass(*cls, \"disabled\") {\n\t\t\treturn &publishButton{elem: oldButton}, \"旧版发布按钮包含 disabled class\", nil\n\t\t}\n\n\t\treturn &publishButton{elem: oldButton}, \"\", nil\n\t}\n\n\treturn nil, \"\", nil\n}\n\nfunc clickPublishWidget(page *rod.Page, widget *rod.Element) error {\n\tif err := widget.ScrollIntoView(); err != nil {\n\t\treturn errors.Wrap(err, \"滚动新版发布按钮到可视区域失败\")\n\t}\n\ttime.Sleep(200 * time.Millisecond)\n\n\tshape, err := widget.Shape()\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"获取新版发布按钮位置失败\")\n\t}\n\tif len(shape.Quads) == 0 {\n\t\treturn errors.New(\"获取新版发布按钮位置失败: 无可点击区域\")\n\t}\n\n\tquad := shape.Quads[0]\n\tminX, maxX := quad[0], quad[0]\n\tminY, maxY := quad[1], quad[1]\n\tfor i := 0; i < quad.Len(); i++ {\n\t\tx := quad[i*2]\n\t\ty := quad[i*2+1]\n\t\tif x < minX {\n\t\t\tminX = x\n\t\t}\n\t\tif x > maxX {\n\t\t\tmaxX = x\n\t\t}\n\t\tif y < minY {","sourceCodeStart":535,"sourceCodeEnd":571,"githubUrl":"https://github.com/xpzouying/xiaohongshu-mcp/blob/332d196854a9eac0d2b8c2c0e3d0cc43139d724c/xiaohongshu/publish.go#L535-L571","documentation":"clickPublishWidget wraps the error from rod's Element.Shape, which fetches the button's geometry (content quads) via CDP. It fails when the element cannot provide a shape — typically because it is detached/hidden or the CDP session is broken. Note the same message also appears as a plain errors.New when Shape succeeds but returns zero quads (no clickable area).","triggerScenarios":"Element.Shape on the `xhs-publish-btn` widget after it was removed from the DOM; the widget has display:none / zero-size layout so no content quads exist; tab closed before the shape query; CDP connection failure.","commonSituations":"Clicking immediately after page load before the web component lays out; page re-render between ScrollIntoView and Shape; viewport minimized or widget collapsed; headless Chrome crashed.","solutions":["Retry with a fresh element: re-run find + click instead of reusing a stale rod.Element handle","Add a short stability wait before clicking so the widget finishes layout (WaitStable / WaitDOMStable)","Check element visibility before clicking (isElementVisible equivalent) to skip zero-size/detached widgets","Verify the browser connection is alive; re-launch Chrome and reopen the publish page if the session died"],"exampleFix":"// before\nshape, err := widget.Shape()\nif err != nil {\n    return errors.Wrap(err, \"获取新版发布按钮位置失败\")\n}\n// after\nif err := page.WaitStable(300 * time.Millisecond); err != nil {\n    return err\n}\nshape, err := widget.Shape()\nif err != nil {\n    return errors.Wrap(err, \"获取新版发布按钮位置失败\")\n}","handlingStrategy":"retry","validationCode":"if !isElementVisible(widget) { return errors.New(\"新版发布按钮不可见\") }\nshape, err := widget.Shape()\nif err != nil || len(shape.Quads) == 0 { return errors.New(\"新版发布按钮无有效形状\") }","typeGuard":"func hasQuads(e *rod.Element) bool {\n    shape, err := e.Shape()\n    return err == nil && len(shape.Quads) > 0\n}","tryCatchPattern":"err := clickPublishButton(page)\nif err != nil && strings.Contains(err.Error(), \"获取新版发布按钮位置失败\") {\n    time.Sleep(500 * time.Millisecond)\n    err = clickPublishButton(page)\n}","preventionTips":["Obtain a fresh element handle immediately before Shape to avoid stale detached nodes","Wait for layout stability (WaitStable) after ScrollIntoView — note the built-in 200ms sleep may be too short on slow machines","Skip widgets with zero quads and continue searching for a valid button","Verify browser connection health; restart the session on repeated Shape failures"],"tags":["browser-automation","rod","cdp","element-shape","element-detached"],"backgroundTag":"cdp-element-detached","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"}