Stealth Chromium that passes every bot detection test. Drop-in Playwright replacement with source-level fingerprint patches. 50+ tests passed.
Python ai-agentsanti-detectantidetect-browserbot-detectionbrowser-automationcaptcha-bypasschromiumcloudflarecloudflare-bypassfingerprintheadless-browserplaywrightpuppeteerpythonrecaptchaseleniumstealth-browserundetectedweb-scrapingwebscraping
fix(async): run blocking launch lookups off the event loop
CloakHQ89fb671af86d
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex db5ffda..9c3973c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,8 @@ Changes are tagged: **[wrapper]** for Python/JS wrapper, **[binary]** for Chromi## [Unreleased]+- **[wrapper]** Async launches no longer freeze the caller's event loop. `launch_async()`, `launch_context_async()` and `launch_persistent_context_async()` ran the binary/license check and the GeoIP and WebRTC exit-IP lookups directly on the event loop, so every other coroutine (a server's health endpoint, WebSockets, other browsers) stalled for up to 20s per launch behind a slow proxy. They now run in a worker thread. .NET: the license check and Pro version lookup inside async launches no longer hold the caller's thread (e.g. a UI thread). Python and .NET; JavaScript was not affected.+## [0.6.2] — 2026-10-12- **[wrapper]** Humanized actions (`click`, `hover`, `fill`, `type`, `check` and the rest) work again on Playwright 1.64. They timed out with `element is not visible` even on visible elements, because Playwright 1.64 changed how it checks visibility. Older Playwright versions are unaffected. Python, JavaScript, and .NET (thanks [@laplace-anon](https://github.com/laplace-anon), #586, #587)diff --git a/README.md b/README.mdindex 0a2dee0..568fcd9 100644--- a/README.md+++ b/README.md@@ -1488,6 +1488,7 @@ Issues and PRs welcome. If something isn't working, [open an issue](https://gith- [@dstosch](https://github.com/dstosch) — cloakserve idle cleanup for browsers launched over HTTP- [@bercedev](https://github.com/bercedev) — humanize support for compiled (Nuitka) Playwright builds- [@laplace-anon](https://github.com/laplace-anon) — humanize fix for Playwright 1.64+- [@theaafofficial](https://github.com/theaafofficial) — non-blocking async launches (GeoIP, WebRTC and license lookups off the event loop)## Star Historydiff --git a/cloakbrowser/browser.py b/cloakbrowser/browser.pyindex 73e5da9..dbd6b16 100644--- a/cloakbrowser/browser.py+++ b/cloakbrowser/browser.py@@ -14,6 +14,7 @@ Usage:from __future__ import annotations+import asyncioimport inspectimport loggingimport os@@ -507,10 +508,12 @@ async def launch_async( # noqa: C901from playwright.async_api import async_playwright- binary_path = ensure_binary(license_key=license_key, browser_version=browser_version, release_channel=release_channel)- timezone, locale, exit_ip = maybe_resolve_geoip(geoip, proxy, timezone, locale, args)+ # Blocking network calls (license/download, exit-IP lookups) run in a thread so+ # they don't freeze the caller's event loop.+ binary_path = await asyncio.to_thread(ensure_binary, license_key=license_key, browser_version=browser_version, release_channel=release_channel)+ timezone, locale, exit_ip = await asyncio.to_thread(maybe_resolve_geoip, geoip, proxy, timezone, locale, args)proxy_kwargs, proxy_extra_args = _resolve_proxy_config(proxy, browser_version, license_key, release_channel)- args = _resolve_webrtc_args(args, proxy)+ args = await asyncio.to_thread(_resolve_webrtc_args, args, proxy)args = _append_webrtc_exit_ip(args, exit_ip)chrome_args = build_args(stealth_args, (args or []) + proxy_extra_args, timezone=timezone, locale=locale, headless=headless, extension_paths=extension_paths, start_maximized=binary_supports_maximized_window(license_key, browser_version, release_channel) and not _suppress_maximize)_maybe_warn_windows_fonts(chrome_args)@@ -819,10 +822,11 @@ async def launch_persistent_context_async(timezone = _resolve_timezone(timezone, kwargs)- binary_path = ensure_binary(license_key=license_key, browser_version=browser_version, release_channel=release_channel)- timezone, locale, exit_ip = maybe_resolve_geoip(geoip, proxy, timezone, locale, args)+ # Blocking network calls run in a thread (see launch_async).+ binary_path = await asyncio.to_thread(ensure_binary, license_key=license_key, browser_version=browser_version, release_channel=release_channel)+ timezone, locale, exit_ip = await asyncio.to_thread(maybe_resolve_geoip, geoip, proxy, timezone, locale, args)proxy_kwargs, proxy_extra_args = _resolve_proxy_config(proxy, browser_version, license_key, release_channel)- args = _resolve_webrtc_args(args, proxy)+ args = await asyncio.to_thread(_resolve_webrtc_args, args, proxy)args = _append_webrtc_exit_ip(args, exit_ip)args = persistent_seed_args(user_data_dir, stealth_args, args)chrome_args = build_args(stealth_args, (args or []) + proxy_extra_args, timezone=timezone, locale=locale, headless=headless, extension_paths=extension_paths, start_maximized=binary_supports_maximized_window(license_key, browser_version, release_channel) and viewport is _VIEWPORT_UNSET and "viewport" not in kwargs and "no_viewport" not in kwargs)@@ -1104,8 +1108,8 @@ async def launch_context_async(timezone = _resolve_timezone(timezone, kwargs)# Resolve geoip BEFORE launch_async() to avoid double-resolution and ensure- # resolved values flow to binary flags- timezone, locale, exit_ip = maybe_resolve_geoip(geoip, proxy, timezone, locale, args)+ # resolved values flow to binary flags. Threaded: the lookup is blocking network I/O.+ timezone, locale, exit_ip = await asyncio.to_thread(maybe_resolve_geoip, geoip, proxy, timezone, locale, args)args = _append_webrtc_exit_ip(args, exit_ip)# --fingerprint-timezone is process-wide (reads CommandLine in renderer),# so it applies to ALL contexts, not just the default one.diff --git a/dotnet/src/CloakBrowser/Download.cs b/dotnet/src/CloakBrowser/Download.csindex c753b31..5ee238e 100644--- a/dotnet/src/CloakBrowser/Download.cs+++ b/dotnet/src/CloakBrowser/Download.cs@@ -235,7 +235,8 @@ public static class Downloadif (!string.IsNullOrEmpty(key)){- var info = License.ValidateLicense(key);+ // Sync HTTP on a cache miss: run it off the caller's thread (e.g. a UI thread).+ var info = await Task.Run(() => License.ValidateLicense(key)).ConfigureAwait(false);if (info != null && info.Valid){// Free tier always gets the latest build. Drop any version pin: the@@ -454,7 +455,7 @@ public static class Download// GetProLatestVersion() is rate-limited to one network call per hour and returns a// cached string in between, so this foreground check stays cheap steady-state.- var latest = License.GetProLatestVersion(releaseChannel);+ var latest = await Task.Run(() => License.GetProLatestVersion(releaseChannel)).ConfigureAwait(false);// Tell the user when they asked for Preview but the server has no preview build// for this platform, so the Stable build is used instead. The lookup is a cache@@ -462,7 +463,7 @@ public static class Download// network on the once-an-hour refresh.if (Config.NormalizeReleaseChannel(releaseChannel) == "preview"){- var release = License.GetProLatestRelease(releaseChannel);+ var release = await Task.Run(() => License.GetProLatestRelease(releaseChannel)).ConfigureAwait(false);if (release is { Fallback: true })WarnPreviewFallback();}@@ -1246,7 +1247,7 @@ public static class Downloadpublic static async Task<string?> CheckForProUpdateAsync(string licenseKey, CancellationToken ct = default, string? releaseChannel = null){- var latest = License.GetProLatestVersion(releaseChannel);+ var latest = await Task.Run(() => License.GetProLatestVersion(releaseChannel)).ConfigureAwait(false);if (string.IsNullOrEmpty(latest)) return null;var effective = Config.GetEffectiveVersion(pro: true, releaseChannel: releaseChannel);diff --git a/dotnet/tests/CloakBrowser.Tests/LicenseTests.cs b/dotnet/tests/CloakBrowser.Tests/LicenseTests.csindex eb4f620..423721b 100644--- a/dotnet/tests/CloakBrowser.Tests/LicenseTests.cs+++ b/dotnet/tests/CloakBrowser.Tests/LicenseTests.cs@@ -232,6 +232,29 @@ public class LicenseTests : IDisposableAssert.Contains("could not be validated", ex.Message);}+ [Fact]+ public async Task EnsureBinaryAsync_does_not_block_the_caller_during_license_validation()+ {+ // Validation is a sync HTTP call; run inline it would hold the caller's thread+ // (e.g. a UI thread) for the whole request.+ using var gate = new ManualResetEventSlim();+ License.ValidateLicenseOverride = _ =>+ {+ gate.Wait(TimeSpan.FromSeconds(2));+ return new LicenseInfo(false, "solo", null);+ };++ var sw = System.Diagnostics.Stopwatch.StartNew();+ var task = Download.EnsureBinaryAsync("cb_slow");+ var returnedAfter = sw.Elapsed;+ var completedOnReturn = task.IsCompleted;+ gate.Set();++ await Assert.ThrowsAsync<InvalidOperationException>(() => task);+ Assert.False(completedOnReturn);+ Assert.True(returnedAfter < TimeSpan.FromSeconds(1), $"caller blocked {returnedAfter}");+ }+// =======================================================================// GetProLatestVersion - rate limiting + marker// =======================================================================diff --git a/tests/test_persistent_context.py b/tests/test_persistent_context.pyindex 4da62f2..f9d72ff 100644--- a/tests/test_persistent_context.py+++ b/tests/test_persistent_context.py@@ -284,6 +284,57 @@ async def test_persistent_context_async_timezone_id_alias(_mock_bin):assert "timezone_id" not in call_kwargs[email protected]("launcher", ["launch_async", "launch_context_async", "launch_persistent_context_async"])+async def test_async_launchers_do_blocking_io_off_the_event_loop(launcher):+ """Binary/license, GeoIP and WebRTC lookups are blocking network calls; on the loop+ they freeze every other coroutine (e.g. a server's health endpoint) for up to 20s."""+ import asyncio+ import threading+ import time++ loop_thread = threading.get_ident()+ threads = []++ def slow(result):+ def call(*_a, **_kw):+ threads.append(threading.get_ident())+ time.sleep(0.2)+ return result(*_a) if callable(result) else result+ return call++ ticks = 0++ async def heartbeat():+ nonlocal ticks+ while True:+ await asyncio.sleep(0.02)+ ticks += 1++ pw_cm, pw, context = _make_mock_async_pw_and_context()+ pw.chromium.launch.return_value = AsyncMock()++ with patch("playwright.async_api.async_playwright", return_value=pw_cm), \+ patch("cloakbrowser.browser.ensure_binary", slow("/fake/chrome")), \+ patch("cloakbrowser.browser.maybe_resolve_geoip", slow(("Europe/Berlin", "de-DE", "5.6.7.8"))), \+ patch("cloakbrowser.browser._resolve_webrtc_args", slow(lambda args, _proxy: args)):+ import cloakbrowser.browser as browser+ beat = asyncio.create_task(heartbeat())+ try:+ if launcher == "launch_persistent_context_async":+ await browser.launch_persistent_context_async("/tmp/profile", geoip=True)+ else:+ await getattr(browser, launcher)(geoip=True)+ finally:+ beat.cancel()++ # 3 calls; 4 via launch_context_async (its inner launch_async re-calls geoip as a no-op)+ assert len(threads) >= 3 and loop_thread not in threads+ assert ticks >= 10 # ~30 over 0.6s at 20ms; a blocked loop gets ~0+ launch = pw.chromium.launch_persistent_context if launcher == "launch_persistent_context_async" else pw.chromium.launch+ assert "--fingerprint-timezone=Europe/Berlin" in launch.call_args[1]["args"]++@patch("cloakbrowser.browser.ensure_binary", return_value="/fake/chrome")@patch("cloakbrowser.browser.maybe_resolve_geoip", return_value=(None, None, None))@patch("cloakbrowser.browser.seed_widevine_hint")