xpzouying/xiaohongshu-mcp · error
查找正文输入框失败
Error message
查找正文输入框失败
What it means
This error is returned by getContentElement after it repeatedly failed to find a visible body content input element within the given timeout. It wraps the last error from findContentElement, meaning none of the candidate CSS selectors (role=textbox, .tiptap, .ql-editor) matched a visible element before the deadline. The publish flow cannot continue without the content editor element.
Source
Thrown at xiaohongshu/publish.go:664
// contentElemSelectors 正文输入框的候选选择器,按先后顺序尝试。
var contentElemSelectors = []string{
`div[role="textbox"][contenteditable="true"]`,
`div.tiptap[contenteditable="true"]`,
`div.ql-editor`,
}
// getContentElement 在 timeout 内轮询查找正文输入框,全部落空返回错误。
func getContentElement(page *rod.Page, timeout time.Duration) (*rod.Element, error) {
deadline := time.Now().Add(timeout)
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
}
}
}View on GitHub (pinned to 332d196854)
Solutions
- Increase the timeout passed to getContentElement if the page loads slowly.
- Verify the publish page actually loaded the editor (check login state, page URL, screenshots).
- Update contentElemSelectors in xiaohongshu/publish.go if the site DOM changed (inspect the live editor).
- Check whether the editor lives in an iframe and extend search to iframe pages.
Example fix
// before elem, err := getContentElement(page, 5*time.Second) // after elem, err := getContentElement(page, 30*time.Second) // allow slow editor load
Defensive patterns
Strategy: retry
Validate before calling
// verify the editor actually rendered before publishing
time.Sleep(3 * time.Second) // or wait for a page-load signal
if has, _, _ := page.Has(`div[role="textbox"][contenteditable="true"]`); !has {
return errors.New("编辑器未加载,取消发布")
} Type guard
func contentEditorVisible(page *rod.Page) bool {
for _, sel := range []string{
`div[role="textbox"][contenteditable="true"]`,
`div.tiptap[contenteditable="true"]`,
`div.ql-editor`,
} {
if has, _, _ := page.Has(sel); has {
return true
}
}
return false
} Try / catch
err := publisher.Publish(ctx, opts)
if err != nil && strings.Contains(err.Error(), "查找正文输入框失败") {
// editor never appeared: reload the publish page and retry once
page.Reload()
err = publisher.Publish(ctx, opts)
} Prevention
- Use a generous timeout for editor load on slow networks
- Confirm login state and correct publish URL before starting
- Screenshot the page on failure to diagnose missing editor
- Update selectors after site front-end updates
When it happens
Trigger: submitPublish or submitPublishVideo calls getContentElement(page, timeout); every poll of findContentElement either errors on page.Elements or finds no visible element, and the deadline expires — the error wraps the last failure.
Common situations: Publish page not fully loaded or showing a different editor variant; Xiaohongshu updated its editor DOM so selectors no longer match; editor is inside an iframe not being searched; page failed to load due to network/login issues.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/1056426cd27e0079.
Report an issue: GitHub.