xpzouying/xiaohongshu-mcp · error
不支持的可见范围: %s,支持: 公开可见、仅自己可见、仅互关好友可见
Error message
不支持的可见范围: %s,支持: 公开可见、仅自己可见、仅互关好友可见
What it means
setVisibility rejects a visibility value not in its supported set before touching the UI. Only 公开可见 (default, empty string), 仅自己可见, and 仅互关好友可见 are supported; anything else returns this errors.Errorf immediately. It is a client-side input validation, not a browser failure.
Source
Thrown at xiaohongshu/publish.go:885
// hasExactClass 检查 class 字符串是否包含指定的完整类名(单词边界匹配)
func hasExactClass(classStr, className string) bool {
pattern := `\b` + regexp.QuoteMeta(className) + `\b`
matched, _ := regexp.MatchString(pattern, classStr)
return matched
}
// setVisibility 设置可见范围
// 支持: "公开可见"(默认), "仅自己可见", "仅互关好友可见"
func setVisibility(page *rod.Page, visibility string) error {
if visibility == "" || visibility == "公开可见" {
slog.Info("可见范围使用默认:公开可见")
return nil
}
supported := map[string]bool{"仅自己可见": true, "仅互关好友可见": true}
if !supported[visibility] {
return errors.Errorf("不支持的可见范围: %s,支持: 公开可见、仅自己可见、仅互关好友可见", visibility)
}
dropdown, err := page.Element("div.permission-card-wrapper div.d-select-content")
if err != nil {
return errors.Wrap(err, "查找可见范围下拉框失败")
}
if err := humanize.Click(dropdown); err != nil {
return errors.Wrap(err, "点击可见范围下拉框失败")
}
time.Sleep(500 * time.Millisecond)
// 在弹窗中查找并点击目标选项
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()View on GitHub (pinned to 332d196854)
Solutions
- Use exactly one of: "" / "公开可见", "仅自己可见", "仅互关好友可见".
- Trim whitespace and normalize the input before calling.
- Add the new value to the supported map only after verifying the option exists in the UI.
- Validate visibility in your own config loading layer before invoking publish.
Example fix
// before visibility = "private" err := submitPublish(page, ..., visibility) // after visibility = "仅自己可见" // 或 "公开可见" / "仅互关好友可见" err := submitPublish(page, ..., visibility)
Defensive patterns
Strategy: validation
Validate before calling
var allowed = map[string]bool{"": true, "公开可见": true, "仅自己可见": true, "仅互关好友可见": true}
if !allowed[visibility] { return fmt.Errorf("非法 visibility: %q", visibility) } Type guard
func validVisibility(v string) bool { return v == "" || v == "公开可见" || v == "仅自己可见" || v == "仅互关好友可见" } Try / catch
if err := submitPublish(page, post, visibility); err != nil {
if strings.Contains(err.Error(), "不支持的可见范围") {
return submitPublish(page, post, "") // 回退默认公开
}
return err
} Prevention
- Validate visibility at config-load time
- Use a fixed enum/const set, not free-form strings
- Trim and normalize user input before passing through
When it happens
Trigger: Calling submitPublish/submitPublishVideo (or setVisibility) with visibility like "私密", "好友可见", or any non-empty string outside the supported map and not equal to "公开可见".
Common situations: Config files or CLI flags passing English values ('public','private'), typos, or newer Xiaohongshu options not yet mapped in the library.
Related errors
AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05).
Data as JSON: /api/errors/a6b3135b2a909dc3.
Report an issue: GitHub.