Skip to content

refactor(xiaohongshu): replace blind retry with MutationObserver wait#730

Merged
jackwener merged 2 commits intomainfrom
fix/xhs-search-wait-for-content
Apr 3, 2026
Merged

refactor(xiaohongshu): replace blind retry with MutationObserver wait#730
jackwener merged 2 commits intomainfrom
fix/xhs-search-wait-for-content

Conversation

@jackwener
Copy link
Copy Markdown
Owner

Summary

  • Replaces the ugly fetchAttempt() + full re-navigation retry from PR fix(xiaohongshu): retry once when first pass returns empty results #681 with a MutationObserver-based wait
  • Waits for section.note-item or login wall text to appear in the DOM (5s timeout), resolving as soon as content renders
  • Faster: no fixed 3s page.wait() before checking content, no 6-7s retry path
  • More correct: addresses the root cause (delayed hydration) instead of working around it

Test plan

  • tsc --noEmit passes
  • All 11 xiaohongshu search tests pass (updated to reflect new evaluate sequence)
  • Retry test replaced with MutationObserver wait test verifying single navigation + 3 evaluate calls

Instead of retrying the entire navigation when search results are empty,
use a MutationObserver to wait for `section.note-item` elements (or login
wall text) to appear in the DOM, with a 5s timeout. This is faster (resolves
as soon as content renders) and more correct (addresses the root cause of
delayed hydration rather than working around it with a full re-navigation).
WAIT_FOR_CONTENT_JS now returns 'content', 'login_wall', or 'timeout'
instead of just true/false. This eliminates the separate login-wall
evaluate call and the redundant loginWall field in the extraction payload.
Two evaluate calls total (wait + extract) instead of three.
@jackwener jackwener merged commit 988908f into main Apr 3, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant