crawl4ai
crawl4ai copied to clipboard
fix: scan_full_page captures all content on virtual-scroll pages (#731)
Summary
_handle_full_page_scan: installs aMutationObserverbefore scrolling to capture DOM elements that are removed during scroll (virtual scroll recycling). After scrolling, deduplicates against still-visible elements and re-injects accumulated content into a hidden<div>sopage.content()includes everything._handle_virtual_scroll: falls back towindow.scrollBy()whencontainer.scrollTophas no effect (window-level scrolling, e.g. Twitter/X). Updates end-of-scroll detection accordingly.- Non-virtual-scroll pages are unaffected: if no elements are removed during scrolling, no injection occurs.
Before fix: scan_full_page=True on a 50-item virtual-scroll page → only 10 items (last batch)
After fix: all 50 items captured
Fixes #731, related to #1087
Test plan
- [x] Reproduction test (
tests/test_repro_731.py) — local virtual-scroll page with 50 items, verifies all 50 captured - [x] 13 adversarial tests covering: virtual scroll (50/100 items), static pages (no false positives), empty pages, append-based infinite scroll, nested virtual scroll with header/footer preservation, low max_steps, observer cleanup, element ordering, hidden container verification, deduplication
- [x] Full regression suite: 303 passed, 0 regressions (1 pre-existing HuggingFace failure unrelated)
🤖 Generated with Claude Code
Reworked based on your review. Force-pushed with the scroll-and-snapshot approach:
- Replaced MutationObserver with a
Map<fingerprint, outerHTML>loop - Fingerprinting uses
id/data-*attributes first, content hash fallback - Accumulator capped at 10K elements
- Kept the
window.scrollByfallback - Real pytest tests with
@pytest.mark.asyncio— 9 adversarial cases (1000 items, similar text, no data-id, append-only, memory stress)
Sorry about the detour through #1877 — consolidated everything back here.