Skip to content

Latest commit

 

History

History
119 lines (83 loc) · 3.6 KB

BROWSER.md

File metadata and controls

119 lines (83 loc) · 3.6 KB

Browser, humanize & detection architecture

Parent: ARCHITECTURE
Code: webvac/utils/browser.py, browser_pool.py, humanize.py, detection.py, consent.py, screenshot.py


1. Goals

  • One Chromium, N isolated contexts (slots) with optional per-slot proxy/UA/geo identity.
  • Human-like warmup, mouse, and scroll to reduce easy bot signals.
  • Shared bot/CAPTCHA detection used by crawl flow and screenshots.
  • Consent cookie/URL bypasses for known CMP patterns.

2. Pool model

flowchart TB
  BM[BrowserManager] --> Chromium[Shared Chromium]
  BM --> S0[BrowserSlot 0]
  BM --> S1[BrowserSlot 1]
  BM --> SN[BrowserSlot N]
  S0 --> ID0[SlotIdentity]
  S1 --> ID1[SlotIdentity]
  ID0 --> UA[UA + Sec-CH-UA]
  ID0 --> Proxy[Proxy dict]
  ID0 --> Geo[Optional city/lat/lon/tz]
Loading
Concept Detail
BrowserSlot Context + lock + identity
new_page(slot) Page inside that context
rotate_proxy Rebuild slot with new proxy identity
set_auth_session / broadcast_auth_session Apply storage_state
capture_auth_session Export storage_state after login

3. Humanize

Module: humanize.py · flags via session_config

Switch Behavior
humanize Master enable
humanize_warmup / ensure_host_warmup Once per host: visit site root → idle → settle → skim
humanize_after_goto / settle_page Micro-moves after successful loads
Scroll _scroll_page uses humanized wheel paths
Evasion Extra human_warmup after proxy rotate
Viewport / screen Context viewport, Playwright screen, and outer*/screen.* init spoofs stay aligned

CLI: --no-humanize, --no-humanize-warmup.

Cursor paths use bezier curves with per-page last-position memory (get_cursor / set_cursor).

Viewport / screen alignment

Bot scripts often compare window.innerWidth (Playwright viewport) with screen.width / window.outerWidth. WebVac now:

  1. Picks slot-0 viewport before Chromium launch so --window-size matches
  2. Passes matching viewport + screen into each context
  3. Injects init-script overrides for outerWidth / outerHeight / screen.* / devicePixelRatio

4. Bot detection

Module: detection.py

flowchart TD
  In[page + response] --> Wall{auth wall?}
  Wall -->|yes| False[return False — not a bot block]
  Wall -->|no| St{status in 403/429/503?}
  St -->|yes| True[bot]
  St -->|no| URL[URL keywords]
  URL --> Title[Blocked titles]
  Title --> Body[Body markers]
  Body --> Out[True/False]
Loading

Signals include Cloudflare “just a moment”, captcha titles, __cf_chl, hCaptcha/reCAPTCHA DOM, DataDome, PerimeterX, etc.

Challenge wait

wait_for_challenge_resolution / is_challenge_in_progress wait up to challenge_wait_ms (default 45s) for transient CF JS challenges before hard-flagging.

Used by BrowserManager.check_for_bot and Crawler._after_goto.


5. Consent

Module: consent.py

  • URL rewrites (e.g. known CMP bypass query params)
  • Cookie injection for Google/Bing-style consent cookies where applicable
  • _handle_consent / --pause-for-consent (headed) / --no-consent-dismiss

6. Screenshots

Module: screenshot.py

  • Captures only when bot/CAPTCHA detected (capture_if_blocked / capture_forced)
  • Bound to {scan}/assets/screenshots/
  • Disable: --no-screenshots

7. Related

  • CRAWL — when warmup / bot check run
  • AUTH — why walls short-circuit detection
  • PROXY_ORIGIN — identity pin with residential playbook