xpzouying/xiaohongshu-mcp · error
查找正文输入框失败: %s
Error message
查找正文输入框失败: %s
What it means
This error is wrapped by findContentElement when page.Elements(selector) itself fails for one of the content-element candidate selectors (e.g. invalid selector or CDP query error). Unlike a mere 'not found' result, this indicates the DOM query call errored, and the selector that failed is included in the message. getContentElement keeps polling and eventually wraps this as '查找正文输入框失败' if it never recovers.
Source
Thrown at xiaohongshu/publish.go:674
for {
elem, err := findContentElement(page)
if err == nil {
return elem, nil
}
if time.Now().After(deadline) {
return nil, errors.Wrap(err, "查找正文输入框失败")
}
time.Sleep(300 * time.Millisecond)
}
}
func findContentElement(page *rod.Page) (*rod.Element, error) {
for _, selector := range contentElemSelectors {
elems, err := page.Elements(selector)
if err != nil {
return nil, errors.Wrapf(err, "查找正文输入框失败: %s", selector)
}
for _, elem := range elems {
if isElementVisible(elem) {
return elem, nil
}
}
}
return findTextboxByPlaceholder(page)
}
func inputTags(ctx context.Context, contentElem *rod.Element, tags []string) error {
if len(tags) == 0 {
return nil
}
time.Sleep(1 * time.Second)View on GitHub (pinned to 332d196854)
Solutions
- Check the wrapped cause and the selector in the message; verify the selector syntax is valid CSS.
- Ensure the browser page is still open and connected (not navigated away or closed).
- Restart the browser session and retry the publish.
- If a selector is obsolete/broken, remove or fix it in contentElemSelectors.
Example fix
// before `div[role="textbox"][contenteditable="true"]`, // ok `div.tiptap[contenteditable=true]`, // invalid: unquoted attribute value // after `div[role="textbox"][contenteditable="true"]`, `div.tiptap[contenteditable="true"]`,
Defensive patterns
Strategy: fallback
Validate before calling
// sanity-check selectors are valid CSS before the flow runs
for _, sel := range selectors {
if _, err := page.Elements(sel); err != nil {
log.Printf("无效选择器 %s: %v", sel, err)
}
} Try / catch
err := publisher.Publish(ctx, opts)
if err != nil && strings.Contains(err.Error(), "查找正文输入框失败: ") {
sel := extractSelector(err.Error())
log.Printf("选择器查询出错: %s,请检查浏览器连接", sel)
// reconnect browser / reopen page, then retry
} Prevention
- Validate all selectors as proper CSS (quote attribute values)
- Keep the browser process and tab alive for the whole flow
- Monitor CDP connection health; reconnect on drop
- Remove obsolete selectors from the candidate list
When it happens
Trigger: During publish, findContentElement iterates contentElemSelectors; a call to page.Elements returns an error — commonly due to an invalid selector string, a detached/closed page, or browser connection failure.
Common situations: Malformed selector after hand-editing contentElemSelectors; browser/tab closed mid-run; rod browser process crashed; CDP connection dropped.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/c1a42cd5d17b3d88.
Report an issue: GitHub.