-
-
Couldn't load subscription status.
- Fork 5.5k
Simulate realistic mouse movement; remove click events to avoid accid… #1548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughReplaces straight-line mouse moves in the async crawler strategy with randomized quadratic Bezier trajectories: viewport-aware start/end points, a randomized control point, stepped movement along the curve, and small random delays between steps. Overall user-simulation flow is preserved. Changes
Sequence Diagram(s)sequenceDiagram
participant Crawler
participant Strategy as AsyncCrawlerStrategy
participant Browser
participant Mouse
rect #F0F9FF
Crawler->>Strategy: trigger user-simulation
Strategy->>Browser: get viewport size (width,height)
note right of Strategy #F6FFF0: choose random start/end\nwithin viewport and control offsets
Strategy->>Strategy: compute quadratic Bezier control point
Strategy->>Mouse: for each step -> move to next (x,y)
Mouse-->>Browser: dispatch move events (with tiny random delays)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crawl4ai/async_crawler_strategy.py (1)
928-930: Consider slower delays for more human-like movement.The current delay range of 0.001-0.003 seconds (1-3ms) between steps results in very fast mouse movements (15-75ms total for 15-25 steps). Typical human cursor movements take 300-1000ms. While fast movements might be acceptable for anti-detection purposes, consider whether a slightly longer delay range (e.g., 0.005-0.015 seconds) would better simulate natural human behavior without compromising the goal of avoiding detection.
If you'd like to adjust the timing, consider:
await page.mouse.move(x, y) # Random small delay between movements to simulate human behavior - await asyncio.sleep(random.uniform(0.001, 0.003)) + await asyncio.sleep(random.uniform(0.005, 0.015))
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crawl4ai/async_crawler_strategy.py(2 hunks)
🧰 Additional context used
🪛 Ruff (0.14.0)
crawl4ai/async_crawler_strategy.py
908-908: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
909-909: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
910-910: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
911-911: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
915-915: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
916-916: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
919-919: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
930-930: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
🔇 Additional comments (1)
crawl4ai/async_crawler_strategy.py (1)
6-6: LGTM! Import is appropriate for the use case.The
randommodule is correctly used here for simulating human-like mouse movements. The static analysis warnings (S311) about cryptographic suitability are false positives in this context, as the randomness is for UI simulation, not security purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
crawl4ai/async_crawler_strategy.py (1)
906-914: Good fix: viewport_size None guard added.Prevents TypeError and resolves the earlier review concern. Looks solid.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crawl4ai/async_crawler_strategy.py(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
crawl4ai/async_crawler_strategy.py (1)
tests/async/test_dispatchers.py (1)
browser_config(17-18)
🪛 Ruff (0.14.0)
crawl4ai/async_crawler_strategy.py
918-918: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
919-919: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
920-920: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
921-921: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
925-925: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
926-926: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
929-929: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
940-940: Standard pseudo-random generators are not suitable for cryptographic purposes
(S311)
…ental navigation
Summary
when set simulate_user=True
mouse click at 100,100 may trigger page navigation which may raise exception if process_iframes=Ture
(at : page.query_selector_all("iframe"))
Summary by CodeRabbit