xpzouying/xiaohongshu-mcp · error

导航到发布页面失败

Error message

导航到发布页面失败

What it means

NewPublishImageAction opens the creator publish page (creator.xiaohongshu.com/publish/publish) via rod's Navigate. '导航到发布页面失败' wraps any Navigate error: navigation was blocked, the request timed out (page had a 300s deadline but ctx/deadline may already be exhausted), the connection failed, or the page was already closed. Callers are publishContent and TestPublish.

Source

Thrown at xiaohongshu/publish.go:48

}

type PublishAction struct {
	page *rod.Page
}

const (
	urlOfPublic = `https://creator.xiaohongshu.com/publish/publish?source=official`

	// contentElemTimeout 查找正文输入框的轮询窗口
	contentElemTimeout = 10 * time.Second
)

func NewPublishImageAction(page *rod.Page) (*PublishAction, error) {

	pp := page.Timeout(300 * time.Second)

	if err := pp.Navigate(urlOfPublic); err != nil {
		return nil, errors.Wrap(err, "导航到发布页面失败")
	}

	if err := pp.WaitLoad(); err != nil {
		logrus.Warnf("等待页面加载出现问题: %v,继续尝试", err)
	}
	time.Sleep(2 * time.Second)

	if err := pp.WaitDOMStable(time.Second, 0.1); err != nil {
		logrus.Warnf("等待 DOM 稳定出现问题: %v,继续尝试", err)
	}
	time.Sleep(1 * time.Second)

	if err := mustClickPublishTab(pp, "上传图文"); err != nil {
		logrus.Errorf("点击上传图文 TAB 失败: %v", err)
		return nil, err
	}

	time.Sleep(1 * time.Second)

View on GitHub (pinned to 332d196854)

Solutions

  1. Check basic connectivity from the host: curl -I https://creator.xiaohongshu.com/publish/publish — if that fails, fix DNS/proxy/firewall first
  2. Set proxy on the rod browser (launcher flags --proxy-server) if the environment requires one
  3. Verify the page/browser is still alive before calling; reuse one long-lived page and guard ctx cancellation
  4. Retry navigation once after a short backoff; transient CDP 'target closed' errors recover on a fresh attempt
  5. If redirected to a login page, ensure the creator account session/cookies are loaded before constructing the action

Example fix

// before
action, err := NewPublishImageAction(page) // page already closed by previous publish
// after
if page != nil && !page.IsClosed() {
    action, err := NewPublishImageAction(page)
} else {
    page := browser.MustPage("about:blank")
    action, err := NewPublishImageAction(page)
}
Defensive patterns

Strategy: retry

Validate before calling

conn, err := net.DialTimeout("tcp", "creator.xiaohongshu.com:443", 5*time.Second)
if err != nil { return fmt.Errorf("creator site unreachable: %w", err) }
conn.Close()

Type guard

func pageUsable(p *rod.Page) bool { return p != nil && !p.IsClosed() }

Try / catch

var action *xiaohongshu.PublishAction
var err error
for i := 0; i < 3; i++ {
    action, err = xiaohongshu.NewPublishImageAction(page)
    if err == nil { break }
    time.Sleep(2*time.Second)
}
if err != nil { return fmt.Errorf("open publish page: %w", err) }

Prevention

When it happens

Trigger: Network outage or DNS failure reaching creator.xiaohongshu.com; the rod browser/page was closed before this call (each call creates a fresh navigation); a proxy or firewall blocks the creator domain; navigation aborted by a redirect to a login/risk-control page that resets the frame; the parent ctx was already canceled when entering the function.

Common situations: Corporate proxy or region blocking creator.xiaohongshu.com; headless server without outbound access; calling Publish twice where the first flow closed the shared page; browser launched without network permissions in CI containers.

Related errors


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/054de6ff20fd6f91. Report an issue: GitHub.