mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2026-11-17 04:48:03 +00:00
Every request builds a new InvisiblePlaywright, and its __aenter__ calls prepare_session_geo(): with the default timezone="" and no proxy that discovers the egress IP through api.ipify.org, icanhazip.com and checkip.amazonaws.com, then calls ensure_geoip_mmdb(), which HEADs GitHub for a newer GeoIP release, three times per session. On a network where those hosts are slow or blocked every request paid for it before the browser even started. Measured in the app image: ipify black-holed adds ~5s per request, all three echo hosts black-holed ~12.5s, GitHub black-holed ~75s. Setting BROWSER_LOCALE alone did not help, because the timezone was still "auto". Without a proxy the egress is the host's own, so the answer does not change between requests. Resolve it on the first request, off the event loop and under a lock so concurrent first requests share one lookup, then hand the zone and the locale's primary tag to InvisiblePlaywright explicitly; an explicit zone and tag make prepare_session_geo touch no network. The resulting browser is the same as with "auto": passing the primary tag back reproduces the decided language list for every Firefox build the locale table can pick, and without a proxy the egress IP, coordinates and srflx are not used by InvisiblePlaywright anyway. When the lookup fails upstream falls back to the host timezone by passing "", but passing "" again would repeat the lookup on every request, so the host zone is named explicitly (TZ, else the /etc/localtime link, else UTC) and the lookup is retried after ten minutes. Sessions behind a proxy (PROXY_SERVER or X-Proxy-Server) still resolve per request through the proxy: each proxy has its own egress, and upstream deliberately fails the launch when it cannot be resolved. BROWSER_TIMEZONE mirrors BROWSER_LOCALE and wins also behind a proxy; with both set the lookup is skipped entirely. Fixes #416 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>