xpzouying/xiaohongshu-mcp · error

未找到声明原创弹窗

Error message

未找到声明原创弹窗

What it means

Thrown by confirmOriginalDeclaration when findFooterByText(page, "声明原创") cannot find any div.footer containing that text — the 声明原创 confirmation dialog is not on the page at that moment. The earlier 须知-footer failure is only a warning, so this is the hard failure point when the modal is missing entirely.

Source

Thrown at xiaohongshu/publish.go:1049

	return errors.New("未找到原创声明选项")
}

// confirmOriginalDeclaration 交互(勾选须知、点声明按钮)走 go-rod 点击;
// 仅用只读 Eval 读取 checkbox 勾选态(不产生交互,无法用属性判断的自定义组件才用)。
func confirmOriginalDeclaration(page *rod.Page) error {
	time.Sleep(800 * time.Millisecond) // 技术等待:等确认弹窗渲染

	if footer, err := findFooterByText(page, "原创声明须知"); err != nil {
		slog.Warn("未找到原创声明确认弹窗的 footer", "error", err)
	} else if err := checkFooterCheckbox(footer); err != nil {
		slog.Warn("勾选原创声明须知失败", "error", err)
	}

	time.Sleep(500 * time.Millisecond) // 技术等待:勾选后等"声明原创"按钮变可用

	footer, err := findFooterByText(page, "声明原创")
	if err != nil {
		return errors.Wrap(err, "未找到声明原创弹窗")
	}

	btn, err := footer.Element("button.custom-button")
	if err != nil {
		return errors.Wrap(err, "未找到声明原创按钮")
	}

	if isButtonDisabled(btn) {
		// 兜底:按钮仍禁用,可能须知未勾上,再勾一次
		if err := checkFooterCheckbox(footer); err != nil {
			slog.Warn("二次勾选须知失败", "error", err)
		}
		time.Sleep(300 * time.Millisecond)
		if isButtonDisabled(btn) {
			return errors.New("声明原创按钮仍处于禁用状态")
		}
	}

View on GitHub (pinned to 332d196854)

Solutions

  1. Confirm the toggle actually enabled original-declaration mode (check its checkbox state) before calling confirmOriginalDeclaration.
  2. Wait for the modal text to appear instead of fixed sleeps: page.Wait on body text containing 声明原创.
  3. Dump page.HTML() on failure; if the dialog markup changed, update findFooterByText's div.footer selector.
  4. Verify the account/flow actually triggers the confirmation dialog and handle a no-modal case gracefully.

Example fix

// before
time.Sleep(500 * time.Millisecond)
footer, err := findFooterByText(page, "声明原创")
if err != nil {
	return errors.Wrap(err, "未找到声明原创弹窗")
}
// after
time.Sleep(500 * time.Millisecond)
if err := page.Wait("() => document.body.innerText.includes('声明原创')"); err != nil {
	return errors.Wrap(err, "声明原创弹窗未渲染")
}
footer, err := findFooterByText(page, "声明原创")
if err != nil {
	return errors.Wrap(err, "未找到声明原创弹窗")
}
Defensive patterns

Strategy: validation

Validate before calling

if err := page.Wait("() => document.body.innerText.includes('声明原创')"); err != nil {
	return fmt.Errorf("声明原创弹窗未渲染: %w", err)
}

Try / catch

if err := setOriginal(page); err != nil {
	if strings.Contains(err.Error(), "未找到声明原创弹窗") {
		html, _ := page.HTML()
		slog.Warn("original-declaration dialog missing", "htmlLen", len(html))
	}
	return err
}

Prevention

When it happens

Trigger: The modal never opened because the toggle click did not register; the modal closed unexpectedly; XHS changed the dialog markup so its footer no longer matches div.footer; fixed sleeps elapsed before the modal rendered and rod's timeout also passed.

Common situations: Slow rendering environments; XHS A/B test replacing the dialog structure; the front-end silently rejecting the toggle (account not eligible for original declaration).

Related errors


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