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: support Playwright 1.65, remove the version cap (#641)
CloakHQ0d7f05c0e4cf
diff --git a/cloakbrowser/human/engine.py b/cloakbrowser/human/engine.pyindex 2c5fab2..9868ccd 100644--- a/cloakbrowser/human/engine.py+++ b/cloakbrowser/human/engine.py@@ -26,7 +26,10 @@ import timefrom typing import Any, Awaitable, Callable, Dict, List, Optional, Sequence, Tuplefrom playwright._impl._errors import Error, TimeoutError-from playwright._impl._js_handle import JSHandle+try: # playwright >= 1.65+ from playwright._impl.js_handle import JSHandle+except ImportError:+ from playwright._impl._js_handle import JSHandlefrom . import fieldsfrom .config import HumanConfig, merge_config, rand, rand_int_range, rand_log, rand_range@@ -327,7 +330,7 @@ class Human:cfg = cfg or self.cfgself.cursor.x = round(rand(*cfg.initial_cursor_x))self.cursor.y = round(rand(*cfg.initial_cursor_y))- await self.mouse.move(self.cursor.x, self.cursor.y)+ await self.mouse.move(self.cursor.x, self.cursor.y, None)self.cursor.initialized = Trueasync def move_to(self, x: float, y: float, cfg: HumanConfig) -> None:@@ -342,7 +345,7 @@ class Human:# comes out of the next wait instead of adding to it.clock += dt / 1000await sleep_ms((clock - time.monotonic()) * 1000)- await self.mouse.move(px, py)+ await self.mouse.move(px, py, None)self.cursor.x, self.cursor.y = x, yasync def idle(self, cfg: HumanConfig) -> None:@@ -354,10 +357,10 @@ class Human:while time.monotonic() < end:x += (random.random() - 0.5) * 2 * cfg.idle_drift_pxy += (random.random() - 0.5) * 2 * cfg.idle_drift_px- await self.mouse.move(round(x), round(y))+ await self.mouse.move(round(x), round(y), None)await sleep_ms(min(rand_range(cfg.idle_pause_range), max(0.0, (end - time.monotonic()) * 1000)))# Drift is noise around the resting point, not a new position.- await self.mouse.move(self.cursor.x, self.cursor.y)+ await self.mouse.move(self.cursor.x, self.cursor.y, None)# -- resolution ---------------------------------------------------------@@ -804,11 +807,11 @@ class Human:for n in range(1, max(1, int(click_count)) + 1):hold = delay if delay is not None else rand_range(cfg.click_hold_input if is_input else cfg.click_hold_button)try:- await self.mouse.down(button=button, clickCount=n)+ await self.mouse.down(button, n)await sleep_ms(hold)finally:# Never leave the button down, also when the page stopped answering.- await self.mouse.up(button=button, clickCount=n)+ await self.mouse.up(button, n)if n < click_count:await sleep_ms(delay if delay is not None else rand(60, 140))finally:@@ -1230,14 +1233,14 @@ class Human:await self.hover(dest, {**sub, "position": opts.get("target_position"), "_nested": True}, api=api)returnawait sleep_ms(rand(100, 200))- await self.mouse.down()+ await self.mouse.down(None, None)try:await sleep_ms(rand(80, 150))await self.hover(dest, {**sub, "position": opts.get("target_position"), "force": True, "_nested": True},api=api)await sleep_ms(rand(80, 150))finally:- await self.mouse.up()+ await self.mouse.up(None, None)async def focus(self, target: Target, opts: dict, api: str = "focus", move: bool = False) -> None:deadline = self.deadline(target, opts)@@ -1331,7 +1334,7 @@ class Human:async def mouse_move(self, x: float, y: float, steps: Optional[int] = None) -> None:if steps is not None:await self.ensure_cursor()- await self.mouse.move(x, y, steps=steps)+ await self.mouse.move(x, y, steps)self.cursor.x, self.cursor.y = x, yreturnawait self.move_to(x, y, self.cfg)diff --git a/cloakbrowser/human/patch.py b/cloakbrowser/human/patch.pyindex fe4f663..f0b6574 100644--- a/cloakbrowser/human/patch.py+++ b/cloakbrowser/human/patch.py@@ -51,7 +51,8 @@ def _impl_page(kind: str, impl: Any) -> Any:if kind in ("Locator", "ElementHandle"):return impl._frame._pageif kind in ("Mouse", "Keyboard"):- return impl._channel._object+ page = getattr(impl, "_page", None) # playwright >= 1.65+ return page if page is not None else impl._channel._objectreturn None # pragma: no cover@@ -89,8 +90,12 @@ def _check_playwright() -> None:except PackageNotFoundError: # pragma: no cover - vendored / editable installsinstalled = "unknown"parts = tuple(int(x) for x in installed.split(".")[:2] if x.isdigit())- from playwright._impl._element_handle import ElementHandle- from playwright._impl._frame import Frame+ try: # playwright >= 1.65+ from playwright._impl.element_handle import ElementHandle+ from playwright._impl.frame import Frame+ except ImportError:+ from playwright._impl._element_handle import ElementHandle+ from playwright._impl._frame import Framemissing = [n for n, ok in (("Frame._timeout", hasattr(Frame, "_timeout")),("ElementHandle._frame", _assigns_attr(ElementHandle.__init__, "_frame")))diff --git a/cloakbrowser/human/world.py b/cloakbrowser/human/world.pyindex 80dbf9b..22d7e66 100644--- a/cloakbrowser/human/world.py+++ b/cloakbrowser/human/world.py@@ -80,6 +80,10 @@ async def bounded(aw: Awaitable[Any]) -> Any:raise PageStalled()+def _send_needs_timeout(fn: Any) -> bool:+ return "timeout" in inspect.signature(fn).parameters++class BoundedCalls:"""``obj`` with every coroutine method going through ``bounded``."""@@ -92,6 +96,8 @@ class BoundedCalls:return attrasync def call(*args: Any, **kwargs: Any) -> Any:+ if name == "send" and _send_needs_timeout(attr): # CDPSession.send, playwright >= 1.65+ args = (args + (None,))[:2] + (None,)return await bounded(attr(*args, **kwargs))return calldiff --git a/js/package-lock.json b/js/package-lock.jsonindex a01038f..657e83b 100644--- a/js/package-lock.json+++ b/js/package-lock.json@@ -17,7 +17,7 @@"devDependencies": {"@types/node": "^26.0.1","mmdb-lib": "^3.0.2",- "playwright-core": "1.64",+ "playwright-core": "1.65","puppeteer-core": "^25.0.4","socks-proxy-agent": "^10.0.0","typescript": "^7.0.2",@@ -28,7 +28,7 @@},"peerDependencies": {"mmdb-lib": ">=2.0.0",- "playwright-core": ">=1.53.0 <1.65.0",+ "playwright-core": ">=1.53.0","puppeteer-core": ">=21.0.0","socks-proxy-agent": ">=10.0.0"},@@ -1495,9 +1495,9 @@}},"node_modules/playwright-core": {- "version": "1.64.1",- "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz",- "integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==",+ "version": "1.65.0",+ "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.0.tgz",+ "integrity": "sha512-vNSKgH6YqtN7cdT/L334zo0a+YwkrpicyrHJlWWPIm/Q+Nn2SWInil01oT0mbu96U4GgoRtCYQD9CzJQgju+lA==","dev": true,"license": "Apache-2.0","bin": {diff --git a/js/package.json b/js/package.jsonindex f6639c8..303eabb 100644--- a/js/package.json+++ b/js/package.json@@ -59,7 +59,7 @@},"peerDependencies": {"mmdb-lib": ">=2.0.0",- "playwright-core": ">=1.53.0 <1.65.0",+ "playwright-core": ">=1.53.0","puppeteer-core": ">=21.0.0","socks-proxy-agent": ">=10.0.0"},@@ -83,7 +83,7 @@"devDependencies": {"@types/node": "^26.0.1","mmdb-lib": "^3.0.2",- "playwright-core": "1.64",+ "playwright-core": "1.65","puppeteer-core": "^25.0.4","socks-proxy-agent": "^10.0.0","typescript": "^7.0.2",diff --git a/pyproject.toml b/pyproject.tomlindex 92a57f2..8c05183 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -49,7 +49,7 @@ classifiers = ["Topic :: Software Development :: Testing",]dependencies = [- "playwright>=1.53,<1.65",+ "playwright>=1.53","httpx>=0.24","cryptography>=41.0", # verify Ed25519 signature on SHA256SUMS before trusting it]diff --git a/tests/test_humanize_unit.py b/tests/test_humanize_unit.pyindex 07489a3..620de01 100644--- a/tests/test_humanize_unit.py+++ b/tests/test_humanize_unit.py@@ -937,7 +937,10 @@ def test_error_classes_stay_importable():def test_check_playwright_accepts_a_compiled_playwright(monkeypatch):"""A Nuitka build swaps function bytecode for a placeholder, so theinternals probe must not report a supported Playwright as broken."""- from playwright._impl._element_handle import ElementHandle+ try:+ from playwright._impl.element_handle import ElementHandle+ except ImportError:+ from playwright._impl._element_handle import ElementHandlefrom cloakbrowser.human import patchclass _CompiledFunction: # stands in for Nuitka's compiled_function@@ -948,7 +951,10 @@ def test_check_playwright_accepts_a_compiled_playwright(monkeypatch):def test_check_playwright_still_flags_missing_internals(monkeypatch):- from playwright._impl._element_handle import ElementHandle+ try:+ from playwright._impl.element_handle import ElementHandle+ except ImportError:+ from playwright._impl._element_handle import ElementHandlefrom cloakbrowser.human import patchdef __init__(self, parent, type, guid, initializer):