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(cloakserve): enable WebSocket heartbeat on client connections (#622)
Pujitha Paladugu062a4dc74dc0
diff --git a/bin/cloakserve b/bin/cloakserveindex f516981..e5c1f99 100755--- a/bin/cloakserve+++ b/bin/cloakserve@@ -683,6 +683,12 @@ async def handle_json_list(request: web.Request) -> web.Response:# WebSocket proxy# ---------------------------------------------------------------------------+# Ping interval for client connections. A client that vanishes without closing+# (crash, SIGKILL, network drop) is otherwise only noticed at the OS TCP timeout,+# which keeps the connection refcount up and blocks --idle-timeout cleanup.+WS_HEARTBEAT_SECONDS = 30++async def proxy_cdp_websocket(client_ws: web.WebSocketResponse,target_url: str,@@ -741,7 +747,7 @@ async def handle_ws_default(request: web.Request) -> web.StreamResponse:cp = await pool.get_or_launch(seed=None)- ws = web.WebSocketResponse()+ ws = web.WebSocketResponse(heartbeat=WS_HEARTBEAT_SECONDS)await ws.prepare(request)pool.connect("__default__")@@ -765,7 +771,7 @@ async def handle_ws_seed(request: web.Request) -> web.StreamResponse:cp = await pool.get_or_launch(seed=seed)- ws = web.WebSocketResponse()+ ws = web.WebSocketResponse(heartbeat=WS_HEARTBEAT_SECONDS)await ws.prepare(request)pool.connect(seed)diff --git a/tests/test_cloakserve.py b/tests/test_cloakserve.pyindex 66b91c5..6b14337 100644--- a/tests/test_cloakserve.py+++ b/tests/test_cloakserve.py@@ -738,3 +738,42 @@ class TestSafeRmtree:pool._safe_rmtree(traversal)assert victim.exists(), "Traversal path must not be deleted"+++class TestClientHeartbeat:+ """A silently dead client must be detected so the connection is released."""++ def test_dead_client_is_disconnected(self):+ from aiohttp import web+ from aiohttp.test_utils import TestClient, TestServer++ events = []++ class Pool:+ async def get_or_launch(self, seed=None):+ return SimpleNamespace(cdp_port=1)++ def connect(self, key):+ events.append("connect")++ def disconnect(self, key):+ events.append("disconnect")++ async def fake_proxy(client_ws, target_url, label):+ async for _ in client_ws:+ pass++ async def run():+ app = web.Application()+ app["pool"] = Pool()+ app.router.add_get("/devtools/{path:.*}", _mod.handle_ws_default)+ async with TestClient(TestServer(app)) as client:+ # autoping=False: the client never answers server pings.+ ws = await client.ws_connect("/devtools/browser/x", autoping=False)+ await asyncio.sleep(1.0)+ assert "disconnect" in events+ await ws.close()++ with patch.object(_mod, "WS_HEARTBEAT_SECONDS", 0.2), \+ patch.object(_mod, "proxy_cdp_websocket", fake_proxy):+ asyncio.run(run())