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
docs(examples): wait in short steps instead of wait_for_timeout or long sleeps
CloakHQc5aa1b59859a
diff --git a/dotnet/examples/CloakBrowser.Examples/Program.cs b/dotnet/examples/CloakBrowser.Examples/Program.csindex 472f476..25dac09 100644--- a/dotnet/examples/CloakBrowser.Examples/Program.cs+++ b/dotnet/examples/CloakBrowser.Examples/Program.cs@@ -142,16 +142,16 @@ static async Task BotTest()Console.WriteLine($"Keyboard type: {page.Keyboard.GetType().Name}");await page.GotoAsync("https://deviceandbrowserinfo.com/are_you_a_bot");- await page.WaitForTimeoutAsync(2000);+ await Task.Delay(2000);// real humanized actionsawait page.Mouse.MoveAsync(300, 300);await page.Mouse.WheelAsync(0, 500);- await page.WaitForTimeoutAsync(1500);+ await Task.Delay(1500);await page.ScreenshotAsync(new() { Path = "bot-result.png", FullPage = true });Console.WriteLine("Saved bot-result.png");- await page.WaitForTimeoutAsync(4000); // leave time to inspect it visually+ await Task.Delay(4000); // leave time to inspect it visually}static async Task Behavioral()@@ -165,24 +165,24 @@ static async Task Behavioral()await page.GotoAsync("https://deviceandbrowserinfo.com/are_you_a_bot_interactions",new() { WaitUntil = WaitUntilState.DOMContentLoaded });- await page.WaitForTimeoutAsync(3000);+ await Task.Delay(3000);var t0 = DateTime.UtcNow;await page.Locator("#email").ClickAsync();- await page.WaitForTimeoutAsync(300);+ await Task.Delay(300);await page.Locator("#email").FillAsync("[email protected]");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);await page.Locator("#password").ClickAsync();- await page.WaitForTimeoutAsync(300);+ await Task.Delay(300);await page.Locator("#password").FillAsync("SecurePass!123");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);await page.Locator("#loginForm button[type=\"submit\"]").ClickAsync();var elapsedMs = (DateTime.UtcNow - t0).TotalMilliseconds;- await page.WaitForTimeoutAsync(5000);+ await Task.Delay(5000);var body = await page.Locator("body").TextContentAsync() ?? "";@@ -249,7 +249,7 @@ static async Task Visual()async Task Inject(){try { await page.EvaluateAsync(cursorJs); } catch { }- await page.WaitForTimeoutAsync(300);+ await Task.Delay(300);}static long Ms(DateTime t0) => (long)(DateTime.UtcNow - t0).TotalMilliseconds;@@ -262,121 +262,121 @@ static async Task Visual()// SCENARIO 1: Wikipedia searchConsole.WriteLine("\n=== Wikipedia - navigation and search ===");await page.GotoAsync("https://www.wikipedia.org");- await page.WaitForTimeoutAsync(2000); await Inject(); await page.WaitForTimeoutAsync(1000);+ await Task.Delay(2000); await Inject(); await Task.Delay(1000);var t = DateTime.UtcNow;await page.Locator("#searchInput").ClickAsync();Check("click search input", Ms(t) > 200, $"{Ms(t)} ms");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);t = DateTime.UtcNow;await page.Locator("#searchInput").FillAsync("Python programming language");var v = await page.Locator("#searchInput").InputValueAsync();Check("fill search box", v == "Python programming language" && Ms(t) > 2000, $"{Ms(t)} ms, '{v}'");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);t = DateTime.UtcNow;await page.Locator("#searchInput").DblClickAsync();var sel = (await page.EvaluateAsync<string>("() => window.getSelection().toString().trim()")) ?? "";Check("dblclick selects word", sel.Length > 0 && Ms(t) > 200, $"{Ms(t)} ms, '{sel}'");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);t = DateTime.UtcNow;await page.Locator("#searchInput").FillAsync("Artificial intelligence");var v2 = await page.Locator("#searchInput").InputValueAsync();Check("fill replaces text", v2 == "Artificial intelligence" && Ms(t) > 1500, $"{Ms(t)} ms, '{v2}'");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);t = DateTime.UtcNow;await page.Locator("button[type=\"submit\"]").HoverAsync();Check("hover submit", Ms(t) > 100, $"{Ms(t)} ms");- await page.WaitForTimeoutAsync(1000);+ await Task.Delay(1000);// SCENARIO 2: CheckboxesConsole.WriteLine("\n=== Checkboxes - check/uncheck ===");await page.GotoAsync("https://the-internet.herokuapp.com/checkboxes");- await page.WaitForTimeoutAsync(2000); await Inject(); await page.WaitForTimeoutAsync(1000);+ await Task.Delay(2000); await Inject(); await Task.Delay(1000);var cb1 = page.Locator("input[type=\"checkbox\"]").Nth(0);var cb2 = page.Locator("input[type=\"checkbox\"]").Nth(1);- if (await cb1.IsCheckedAsync()) { await cb1.UncheckAsync(); await page.WaitForTimeoutAsync(500); }+ if (await cb1.IsCheckedAsync()) { await cb1.UncheckAsync(); await Task.Delay(500); }t = DateTime.UtcNow;await cb1.CheckAsync();Check("check checkbox 1", await cb1.IsCheckedAsync() && Ms(t) > 200, $"{Ms(t)} ms");- await page.WaitForTimeoutAsync(500);- if (!await cb2.IsCheckedAsync()) { await cb2.CheckAsync(); await page.WaitForTimeoutAsync(500); }+ await Task.Delay(500);+ if (!await cb2.IsCheckedAsync()) { await cb2.CheckAsync(); await Task.Delay(500); }t = DateTime.UtcNow;await cb2.UncheckAsync();Check("uncheck checkbox 2", !await cb2.IsCheckedAsync() && Ms(t) > 200, $"{Ms(t)} ms");- await page.WaitForTimeoutAsync(1000);+ await Task.Delay(1000);// SCENARIO 3: DropdownConsole.WriteLine("\n=== Dropdown - select ===");await page.GotoAsync("https://the-internet.herokuapp.com/dropdown");- await page.WaitForTimeoutAsync(2000); await Inject(); await page.WaitForTimeoutAsync(1000);+ await Task.Delay(2000); await Inject(); await Task.Delay(1000);t = DateTime.UtcNow;await page.Locator("#dropdown").SelectOptionAsync("1");Check("select option 1", await page.Locator("#dropdown").InputValueAsync() == "1" && Ms(t) > 100, $"{Ms(t)} ms");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);t = DateTime.UtcNow;await page.Locator("#dropdown").SelectOptionAsync("2");Check("select option 2", await page.Locator("#dropdown").InputValueAsync() == "2" && Ms(t) > 100, $"{Ms(t)} ms");- await page.WaitForTimeoutAsync(1000);+ await Task.Delay(1000);// SCENARIO 4: Drag and dropConsole.WriteLine("\n=== Drag and Drop - A -> B ===");await page.GotoAsync("https://the-internet.herokuapp.com/drag_and_drop");- await page.WaitForTimeoutAsync(2000); await Inject(); await page.WaitForTimeoutAsync(1000);+ await Task.Delay(2000); await Inject(); await Task.Delay(1000);var beforeA = (await page.Locator("#column-a header").TextContentAsync())?.Trim();t = DateTime.UtcNow;await page.Locator("#column-a").DragToAsync(page.Locator("#column-b"));- await page.WaitForTimeoutAsync(1000);+ await Task.Delay(1000);var afterA = (await page.Locator("#column-a header").TextContentAsync())?.Trim();Check("drag A to B", beforeA != afterA && Ms(t) > 300, $"{Ms(t)} ms, swapped={beforeA != afterA}");- await page.WaitForTimeoutAsync(1000);+ await Task.Delay(1000);// SCENARIO 5: Text editingConsole.WriteLine("\n=== Text editing - type/press/clear/sequential ===");await page.GotoAsync("https://www.wikipedia.org");- await page.WaitForTimeoutAsync(2000); await Inject(); await page.WaitForTimeoutAsync(1000);+ await Task.Delay(2000); await Inject(); await Task.Delay(1000);t = DateTime.UtcNow;await page.Locator("#searchInput").PressSequentiallyAsync("Hello World");var hv = await page.Locator("#searchInput").InputValueAsync();Check("type 'Hello World'", hv == "Hello World" && Ms(t) > 1000, $"{Ms(t)} ms, '{hv}'");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);t = DateTime.UtcNow;await page.Locator("#searchInput").PressAsync("End");await page.Locator("#searchInput").PressAsync("!");var pv = await page.Locator("#searchInput").InputValueAsync();Check("press '!' at end", (pv ?? "").Contains("!") && Ms(t) > 100, $"{Ms(t)} ms, '{pv}'");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);t = DateTime.UtcNow;await page.Locator("#searchInput").ClearAsync();var cv = await page.Locator("#searchInput").InputValueAsync();Check("clear field", cv == "" && Ms(t) > 100, $"{Ms(t)} ms");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);t = DateTime.UtcNow;await page.Locator("#searchInput").PressSequentiallyAsync("Sequential");var sv = await page.Locator("#searchInput").InputValueAsync();Check("press_sequentially", sv == "Sequential" && Ms(t) > 500, $"{Ms(t)} ms, '{sv}'");- await page.WaitForTimeoutAsync(1000);+ await Task.Delay(1000);// SCENARIO 6: Mouse precision + raw keyboardConsole.WriteLine("\n=== Mouse precision + keyboard ===");t = DateTime.UtcNow;await page.Mouse.MoveAsync(600, 400);Check("mouse.move (600,400)", Ms(t) > 100, $"{Ms(t)} ms");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);t = DateTime.UtcNow;await page.Mouse.ClickAsync(200, 200);Check("mouse.click (200,200)", Ms(t) > 100, $"{Ms(t)} ms");- await page.WaitForTimeoutAsync(500);+ await Task.Delay(500);await page.Locator("#searchInput").ClickAsync();- await page.WaitForTimeoutAsync(300);+ await Task.Delay(300);t = DateTime.UtcNow;await page.Keyboard.TypeAsync("Direct keyboard");Check("keyboard.type", Ms(t) > 500, $"{Ms(t)} ms");- await page.WaitForTimeoutAsync(1000);+ await Task.Delay(1000);// SUMMARYConsole.WriteLine("\n" + new string('=', 70));@@ -477,7 +477,7 @@ static async Task WebRtcTest()var page = await browser.NewPageAsync();await page.GotoAsync("https://browserleaks.com/webrtc");- await page.WaitForTimeoutAsync(6000); // give WebRTC time to run+ await Task.Delay(6000); // give WebRTC time to runvar text = await page.InnerTextAsync("body");Console.WriteLine("--- browserleaks WebRTC (looking for IPs) ---");@@ -497,7 +497,7 @@ static async Task TrustedTest()});var page = await browser.NewPageAsync();await page.GotoAsync("https://www.wikipedia.org");- await page.WaitForTimeoutAsync(1500);+ await Task.Delay(1500);// detector: catch untrusted keydown + querySelector from the evaluate contextawait page.EvaluateAsync(@"() => {@@ -519,9 +519,9 @@ static async Task TrustedTest()}");await page.Locator("#searchInput").ClickAsync();- await page.WaitForTimeoutAsync(300);+ await Task.Delay(300);await page.Keyboard.TypeAsync("Hello!@#$%^&*()");- await page.WaitForTimeoutAsync(800);+ await Task.Delay(800);var untrusted = await page.EvaluateAsync<string[]>("() => window.__untrusted");var leaks = await page.EvaluateAsync<string[]>("() => window.__evalLeaks");diff --git a/examples/fingerprint_scan_test.py b/examples/fingerprint_scan_test.pyindex 261de90..a85c2f0 100644--- a/examples/fingerprint_scan_test.py+++ b/examples/fingerprint_scan_test.py@@ -17,6 +17,14 @@ import timefrom cloakbrowser import launch_context++def wait(page, seconds):+ """Wait in 1 s steps: one long sleep can leave a challenge page stuck."""+ for _ in range(seconds):+ page.context.cookies() # keeps Playwright processing, doesn't touch the page+ time.sleep(1)++HEADLESS = "--headless" in sys.argvPROXY = Nonefor i, arg in enumerate(sys.argv):@@ -28,7 +36,7 @@ def test_fingerprint_scan(page):"""fingerprint-scan.com — bot risk score + headless detection signals."""print("=== fingerprint-scan.com ===")page.goto("https://fingerprint-scan.com/", wait_until="domcontentloaded", timeout=30000)- time.sleep(20) # Castle.js needs time to compute score+ wait(page, 20) # Castle.js needs time to compute score# Check bot risk scorescore = page.evaluate(@@ -93,7 +101,7 @@ def test_creepjs(page):"https://abrahamjuliot.github.io/creepjs/", wait_until="domcontentloaded", timeout=30000)print("Waiting 30s for CreepJS analysis...")- time.sleep(30)+ wait(page, 30)# Extract % scores from page text (matches test-infra/matrix_tests/group3_bot_detection.py)scores = page.evaluate("""() => {diff --git a/examples/integrations/aws_lambda/lambda_handler.py b/examples/integrations/aws_lambda/lambda_handler.pyindex 8821e70..edc11b0 100644--- a/examples/integrations/aws_lambda/lambda_handler.py+++ b/examples/integrations/aws_lambda/lambda_handler.py@@ -34,7 +34,7 @@ Event schema (all fields except `url` are optional):wait_for_selector str CSS or XPath selectorwait_for_selector_state str "attached"|"detached"|"visible"|"hidden", default "visible"wait_for_selector_timeout_ms int 30000- wait_ms int fixed pause in ms (page.wait_for_timeout)+ wait_ms int fixed pause in ms (asyncio.sleep)Capture options:screenshot bool True@@ -205,7 +205,7 @@ async def _post_nav_waits(page, event: dict) -> None:timeout=event.get("wait_for_selector_timeout_ms", 30000),)if "wait_ms" in event:- await page.wait_for_timeout(event["wait_ms"])+ await asyncio.sleep(event["wait_ms"] / 1000) # native sleep, not page.wait_for_timeoutasync def _launch_with_retry(event: dict, attempts: int = 3, backoff_s: float = 0.3):diff --git a/examples/stealth_test.py b/examples/stealth_test.pyindex ad3da0a..e90fed7 100644--- a/examples/stealth_test.py+++ b/examples/stealth_test.py@@ -15,6 +15,14 @@ import timefrom cloakbrowser import CloakBrowserLicenseError, launch++def wait(page, seconds):+ """Wait in 1 s steps: one long sleep can leave a challenge page stuck."""+ for _ in range(seconds):+ page.context.cookies() # keeps Playwright processing, doesn't touch the page+ time.sleep(1)++HEADED = "--headed" in sys.argvSCREENSHOTS = "--no-screenshots" not in sys.argvPROXY = None@@ -26,7 +34,7 @@ for i, arg in enumerate(sys.argv):def test_bot_sannysoft(page):"""bot.sannysoft.com — classic bot detection checks."""page.goto("https://bot.sannysoft.com", wait_until="networkidle", timeout=30000)- time.sleep(3)+ wait(page, 3)results = page.evaluate("""() => {const rows = document.querySelectorAll('table tr');@@ -56,7 +64,7 @@ def test_bot_incolumitas(page):last_total = 0results = {"passed": 0, "failed": 0, "failedTests": [], "total": 0}for _ in range(15):- time.sleep(2)+ wait(page, 2)results = page.evaluate("""() => {const text = document.body.innerText;const okMatches = text.match(/"\\w+":\\s*"OK"/g) || [];@@ -74,7 +82,7 @@ def test_bot_incolumitas(page):def test_rebrowser(page):"""bot-detector.rebrowser.net — automation signal detector."""page.goto("https://bot-detector.rebrowser.net/", wait_until="networkidle", timeout=30000)- time.sleep(10)+ wait(page, 10)return page.evaluate("""() => {const el = document.getElementById('detections-json');@@ -90,7 +98,7 @@ def test_rebrowser(page):def test_browserscan(page):"""browserscan.net/bot-detection — WebDriver, UA, CDP, Navigator checks."""page.goto("https://www.browserscan.net/bot-detection", wait_until="networkidle", timeout=30000)- time.sleep(5)+ wait(page, 5)results = page.evaluate("""() => {const items = document.querySelectorAll('[class*="result"], [class*="item"], [class*="check"]');@@ -111,7 +119,7 @@ def test_browserscan(page):def test_deviceandbrowserinfo(page):"""deviceandbrowserinfo.com/are_you_a_bot — fingerprint + behavioral detection."""page.goto("https://deviceandbrowserinfo.com/are_you_a_bot", wait_until="domcontentloaded", timeout=30000)- time.sleep(8)+ wait(page, 8)results = page.evaluate("""() => {const text = document.body.innerText;@@ -136,7 +144,7 @@ def test_deviceandbrowserinfo(page):def test_creepjs(page):"""CreepJS — lies plus like-headless, headless and stealth scores."""page.goto("https://abrahamjuliot.github.io/creepjs/", wait_until="domcontentloaded", timeout=30000)- time.sleep(15)+ wait(page, 15)return page.evaluate("""() => {const fp = window.Fingerprint;@@ -160,7 +168,7 @@ def test_recaptcha(page):)score = Nonefor _ in range(15):- time.sleep(2)+ wait(page, 2)score = page.evaluate("""() => {const match = document.body.innerText.match(/"score":\\s*(\\d+\\.\\d+)/);return match ? parseFloat(match[1]) : null;diff --git a/js/examples/stealth-test.ts b/js/examples/stealth-test.tsindex a5b28a0..a221d38 100644--- a/js/examples/stealth-test.ts+++ b/js/examples/stealth-test.ts@@ -38,7 +38,7 @@ async function testSannysoft() {waitUntil: "networkidle",timeout: 30000,});- await page.waitForTimeout(3000);+ await new Promise((r) => setTimeout(r, 3000));const result = await page.evaluate(() => {const rows = document.querySelectorAll("table tr");@@ -79,7 +79,7 @@ async function testIncolumitas() {waitUntil: "networkidle",timeout: 30000,});- await page.waitForTimeout(12000); // needs time for all detection tests+ await new Promise((r) => setTimeout(r, 12000)); // needs time for all detection testsconst result = await page.evaluate(() => {const text = document.body.innerText;@@ -116,7 +116,7 @@ async function testBrowserScan() {waitUntil: "networkidle",timeout: 30000,});- await page.waitForTimeout(5000);+ await new Promise((r) => setTimeout(r, 5000));const result = await page.evaluate(() => {const text = document.body.innerText;@@ -143,7 +143,7 @@ async function testDeviceAndBrowserInfo() {waitUntil: "domcontentloaded",timeout: 30000,});- await page.waitForTimeout(8000);+ await new Promise((r) => setTimeout(r, 8000));const result = await page.evaluate(() => {const text = document.body.innerText;@@ -187,11 +187,11 @@ async function testFingerprintJS() {waitUntil: "networkidle",timeout: 30000,});- await page.waitForTimeout(5000);+ await new Promise((r) => setTimeout(r, 5000));try {await page.click("button:has-text('Search')", { timeout: 5000 });- await page.waitForTimeout(5000);+ await new Promise((r) => setTimeout(r, 5000));} catch {// Search button may not be present}@@ -225,7 +225,7 @@ async function testRecaptcha() {"https://recaptcha-demo.appspot.com/recaptcha-v3-request-scores.php",{ waitUntil: "networkidle", timeout: 30000 });- await page.waitForTimeout(8000);+ await new Promise((r) => setTimeout(r, 8000));const result = await page.evaluate(() => {const text = document.body.innerText;