Skip to content

Stealth Chromium that passes every bot detection test. Drop-in Playwright replacement with source-level fingerprint patches. 50+ tests passed.

test: drop viewport overrides from the humanize tests

CloakHQ9978b2d1227c
diff --git a/dotnet/tests/CloakBrowser.Tests/HumanEngine/HumanEngineBrowserTests.cs b/dotnet/tests/CloakBrowser.Tests/HumanEngine/HumanEngineBrowserTests.cs
index 4516eb5..e961262 100644
--- a/dotnet/tests/CloakBrowser.Tests/HumanEngine/HumanEngineBrowserTests.cs
+++ b/dotnet/tests/CloakBrowser.Tests/HumanEngine/HumanEngineBrowserTests.cs
@@ -345,7 +345,8 @@ public class HumanEngineBrowserTests : IClassFixture<EngineFixture>, IAsyncLifet
public async Task Scroll_overshoot_wheels_past_the_target_and_back()
{
var p = await OpenWith(new() { ["scroll_overshoot_chance"] = 1.0, ["scroll_overshoot_px"] = new[] { 120.0, 120.0 } });
- await p.SetViewportSizeAsync(800, 300);
+ // A spacer, not a viewport override, puts #chk below the fold.
+ await p.EvaluateAsync("() => document.body.insertAdjacentHTML('afterbegin', `<div style=\"height: ${2 * innerHeight}px\"></div>`)");
await Reset(p);
await p.ClickAsync("#chk");
var dys = (await Events(p, "wheel")).Select(e => e.GetProperty("dy").GetDouble()).ToList();
@@ -372,7 +373,6 @@ public class HumanEngineBrowserTests : IClassFixture<EngineFixture>, IAsyncLifet
public async Task Scroller_follows_the_containing_block_chain(string body, bool clipped)
{
var p = await Open();
- await p.SetViewportSizeAsync(390, 844);
await p.GotoAsync("data:text/html," + Uri.EscapeDataString(CbCss + body));
await p.EvaluateAsync("() => { window.__clicks = 0; document.getElementById('t').addEventListener('click', () => window.__clicks++); }");
await p.ClickAsync("#t", new() { Timeout = 5000 });
diff --git a/js/tests/humanizeEngine.test.ts b/js/tests/humanizeEngine.test.ts
index 23b8135..89a3be4 100644
--- a/js/tests/humanizeEngine.test.ts
+++ b/js/tests/humanizeEngine.test.ts
@@ -420,7 +420,8 @@ describe.skipIf(!process.env.CLOAKBROWSER_BINARY_PATH)('humanize engine (real br
it('scroll overshoot wheels past the target and back', async () => {
const p = await open();
- await p.setViewportSize({ width: 800, height: 300 });
+ // A spacer, not a viewport override, puts #chk below the fold.
+ await p.evaluate(() => document.body.insertAdjacentHTML('afterbegin', `<div style="height: ${2 * innerHeight}px"></div>`));
await reset(p);
await p.click('#chk', { human_config: { scroll_overshoot_chance: 1, scroll_overshoot_px: [120, 120] } });
const dys = (await events(p, 'wheel')).map((e) => e.dy);
@@ -455,7 +456,6 @@ describe.skipIf(!process.env.CLOAKBROWSER_BINARY_PATH)('humanize engine (real br
for (const [name, body, clipped] of CB_CASES) {
it(`scroller follows the containing block: ${name} (#593)`, async () => {
const p = await open();
- await p.setViewportSize({ width: 390, height: 844 });
await p.goto('data:text/html,' + encodeURIComponent(CB_CSS + body));
await p.evaluate(() => { (window as any).__clicks = 0;
document.getElementById('t')!.addEventListener('click', () => (window as any).__clicks++); });
diff --git a/js/tests/humanizePuppeteer.test.ts b/js/tests/humanizePuppeteer.test.ts
index f8e76c8..486394f 100644
--- a/js/tests/humanizePuppeteer.test.ts
+++ b/js/tests/humanizePuppeteer.test.ts
@@ -18,7 +18,6 @@ describe.skipIf(!process.env.CLOAKBROWSER_BINARY_PATH)('humanize: Puppeteer (rea
const open = async (b: Browser = browser): Promise<Page> => {
const page = await b.newPage();
pages.push(page);
- await page.setViewport({ width: 1280, height: 720 });
await page.goto(srv.url + 'index.html');
return page;
};
@@ -61,10 +60,10 @@ describe.skipIf(!process.env.CLOAKBROWSER_BINARY_PATH)('humanize: Puppeteer (rea
});
it('frame.click / type / hover resolve inside the frame (#184)', async () => {
- // Tall viewport: the frame input is already in view, so no wheel scroll can
- // land over the iframe (known gap: Puppeteer's scroll may wheel the iframe).
+ // Bring the iframe into view first, so no wheel scroll can land over it
+ // (known gap: Puppeteer's scroll may wheel the iframe).
const page = await open();
- await page.setViewport({ width: 1280, height: 1400 });
+ await page.evaluate(() => document.querySelector('iframe[name="f"]')!.scrollIntoView());
const f = await frameOf(page);
await reset(f);
await f.click('#finput');
diff --git a/js/tests/stealth.puppeteer.test.ts b/js/tests/stealth.puppeteer.test.ts
index de624bb..6cf05dc 100644
--- a/js/tests/stealth.puppeteer.test.ts
+++ b/js/tests/stealth.puppeteer.test.ts
@@ -2242,10 +2242,12 @@ describeIfSlow("Puppeteer stealth browser: focus() uses click", () => {
}, 30000);
});
+// The left block ends 200 px before the window edge, so only 200 px of the target
+// is on screen at any window width.
const WIDE_ROW_HTML = `
<body style="margin:0">
<div style="display:flex">
- <div style="min-width:800px">left</div>
+ <div style="min-width:calc(100vw - 200px)">left</div>
<button id="target" style="min-width:800px"
onclick="this.textContent = 'CLICKED'">right</button>
</div>
@@ -2257,7 +2259,6 @@ describeIfSlow("Puppeteer stealth browser: horizontal scroll into view (#521)",
const browser = await launch({ humanize: true, headless: true });
try {
const page = await browser.newPage();
- await page.setViewport({ width: 1000, height: 700 });
await page.setContent(WIDE_ROW_HTML);
await page.click("#target");
await sleep(500);
diff --git a/js/tests/stealth.test.ts b/js/tests/stealth.test.ts
index f9b8079..fc6b314 100644
--- a/js/tests/stealth.test.ts
+++ b/js/tests/stealth.test.ts
@@ -901,10 +901,12 @@ describeIfSlow("stealth browser: selector parity and target identity", () => {
});
// page.setContent timed out in local runs of this test, so the page is loaded as a data: URL.
+// The left block ends 200 px before the window edge, so only 200 px of the target
+// is on screen at any window width.
const WIDE_ROW_HTML = `
<body style="margin:0">
<div style="display:flex">
- <div style="min-width:800px">left</div>
+ <div style="min-width:calc(100vw - 200px)">left</div>
<button id="target" style="min-width:800px"
onclick="this.textContent = 'CLICKED'">right</button>
</div>
@@ -915,7 +917,7 @@ describeIfSlow("stealth browser: horizontal scroll into view (#521)", () => {
const { launch } = await import("../src/index.js");
const browser = await launch({ headless: true, humanize: true });
try {
- const page = await browser.newPage({ viewport: { width: 1000, height: 700 } });
+ const page = await browser.newPage();
await page.goto("data:text/html," + encodeURIComponent(WIDE_ROW_HTML));
await page.click("#target", { timeout: 5000 });
expect(await page.locator("#target").textContent()).toBe("CLICKED");
diff --git a/tests/test_humanize_engine.py b/tests/test_humanize_engine.py
index 496a17c..38f2b4d 100644
--- a/tests/test_humanize_engine.py
+++ b/tests/test_humanize_engine.py
@@ -605,7 +605,9 @@ def test_mistypes_are_corrected_and_skip_masked_fields(browser, site):
def test_scroll_overshoot_wheels_back(page):
- page.set_viewport_size({"width": 800, "height": 300})
+ # A spacer, not a viewport override, puts #chk below the fold.
+ page.evaluate("""() => document.body.insertAdjacentHTML('afterbegin',
+ `<div style="height: ${2 * innerHeight}px"></div>`)""")
reset(page)
page.click("#chk", human_config={"scroll_overshoot_chance": 1.0, "scroll_overshoot_px": (120, 120)})
dys = [e["dy"] for e in events(page, "wheel")]
@@ -741,7 +743,6 @@ def test_scroller_follows_the_containing_block_chain(page, name):
scroller; a fixed modal that is a DOM child of a scrolling panel is on
screen and must be clicked, not retried as 'outside of the viewport'."""
body, clipped = _CB_CASES[name]
- page.set_viewport_size({"width": 390, "height": 844})
page.goto("data:text/html," + urllib.parse.quote(_CB_CSS + body))
page.evaluate("""() => { window.__clicks = 0;
document.getElementById('t').addEventListener('click', () => __clicks++); }""")
diff --git a/tests/test_humanize_unit.py b/tests/test_humanize_unit.py
index 620de01..bb14b52 100644
--- a/tests/test_humanize_unit.py
+++ b/tests/test_humanize_unit.py
@@ -643,10 +643,12 @@ class TestBrowserIframeHumanizeAsync:
# page.set_content timed out in local runs of this test, so the page is loaded as a data: URL.
+# The left block ends 200 px before the window edge, so only 200 px of the target
+# is on screen at any window width.
_WIDE_ROW_HTML = """
<body style="margin:0">
<div style="display:flex">
- <div style="min-width:800px">left</div>
+ <div style="min-width:calc(100vw - 200px)">left</div>
<button id="target" style="min-width:800px"
onclick="this.textContent = 'CLICKED'">right</button>
</div>
@@ -664,7 +666,7 @@ class TestBrowserHorizontalScroll:
from cloakbrowser import launch
browser = launch(headless=True, humanize=True, geoip=False)
try:
- page = browser.new_page(viewport={"width": 1000, "height": 700})
+ page = browser.new_page()
page.goto("data:text/html," + quote(_WIDE_ROW_HTML))
page.click("#target", timeout=5000)
assert page.locator("#target").text_content() == "CLICKED"
@@ -676,7 +678,7 @@ class TestBrowserHorizontalScroll:
from cloakbrowser import launch_async
browser = await launch_async(headless=True, humanize=True, geoip=False)
try:
- page = await browser.new_page(viewport={"width": 1000, "height": 700})
+ page = await browser.new_page()
await page.goto("data:text/html," + quote(_WIDE_ROW_HTML))
await page.click("#target", timeout=5000)
assert await page.locator("#target").text_content() == "CLICKED"