xpzouying/xiaohongshu-mcp · error
未找到可见范围选项: %s
Error message
未找到可见范围选项: %s
What it means
setVisibility returns this when the dropdown opened and options were listed, but none of the option texts contained the requested visibility string. The value passed validation (194) yet isn't present as an option in the actual UI popup, so the requested visibility cannot be applied.
Source
Thrown at xiaohongshu/publish.go:916
opts, err := page.Elements("div.d-options-wrapper div.d-grid-item div.custom-option")
if err != nil {
return errors.Wrap(err, "查找可见范围选项失败")
}
for _, opt := range opts {
text, err := opt.Text()
if err != nil {
continue
}
if strings.Contains(text, visibility) {
if err := humanize.Click(opt); err != nil {
return errors.Wrap(err, "选择可见范围失败")
}
slog.Info("已设置可见范围", "visibility", visibility)
time.Sleep(200 * time.Millisecond)
return nil
}
}
return errors.Errorf("未找到可见范围选项: %s", visibility)
}
// setSchedulePublish 设置定时发布时间
func setSchedulePublish(ctx context.Context, page *rod.Page, t time.Time) error {
// 1. 点击定时发布开关
if err := clickScheduleSwitch(page); err != nil {
return err
}
time.Sleep(800 * time.Millisecond)
// 2. 设置日期时间
if err := setDateTime(ctx, page, t); err != nil {
return err
}
time.Sleep(500 * time.Millisecond)
return nil
}View on GitHub (pinned to 332d196854)
Solutions
- Log the collected option texts on failure so you can compare against the requested value.
- Verify the value against the actual UI options for your account type.
- Update the matching logic/labels if the UI text changed.
- Fall back to a safe default (公开可见) or fail the publish early with a clear message.
Example fix
// before
return errors.Errorf("未找到可见范围选项: %s", visibility)
// after
var found []string
for _, o := range opts { if t, _ := o.Text(); t != "" { found = append(found, t) } }
return errors.Errorf("未找到可见范围选项: %s, 可用选项: %v", visibility, found) Defensive patterns
Strategy: fallback
Validate before calling
// 调用前无法完全预知 UI 选项,建议先读取选项文本核对
opts, _ := page.Elements("div.d-options-wrapper div.d-grid-item div.custom-option")
for _, o := range opts { t, _ := o.Text(); slog.Debug("可选范围", "option", t) } Type guard
func visibilityOffered(opts []*rod.Element, want string) bool {
for _, o := range opts { if t, err := o.Text(); err == nil && strings.Contains(t, want) { return true } }
return false
} Try / catch
if err := setVisibility(page, visibility); err != nil {
if strings.Contains(err.Error(), "未找到可见范围选项") {
slog.Warn("目标可见范围不可用,回退公开可见")
return setVisibility(page, "公开可见")
}
return err
} Prevention
- Log available option texts when matching fails
- Confirm the account type offers the requested visibility
- Provide a safe default fallback in the publish flow
When it happens
Trigger: Visibility value valid per the map (e.g. "仅互关好友可见") but the current account/page doesn't offer that option (account type restrictions); option text changed/renamed in the UI; popup listed different options for video vs article publish flow.
Common situations: Enterprise or restricted accounts lacking 仅互关好友可见; Xiaohongshu renaming option labels; caller passing a substring that doesn't match rendered text.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/9b968455f3548858.
Report an issue: GitHub.