diff --git a/src/browser.ts b/src/browser.ts index f271ac0..888bccf 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -91,8 +91,12 @@ export class Browser { this.pages.push(page); const celestial = page.unsafelyGetCelestialBindings(); + const { userAgent } = await celestial.Browser.getVersion(); await Promise.all([ + celestial.Emulation.setUserAgentOverride({ + userAgent: userAgent.replaceAll("Headless", ""), + }), celestial.Page.enable(), celestial.Page.setInterceptFileChooserDialog({ enabled: true }), ]); diff --git a/tests/evaluate_test.ts b/tests/evaluate_test.ts index e8f8257..0ea572c 100644 --- a/tests/evaluate_test.ts +++ b/tests/evaluate_test.ts @@ -1,4 +1,5 @@ import { assertEquals } from "https://deno.land/std@0.198.0/assert/assert_equals.ts"; + import { launch } from "../mod.ts"; Deno.test("Testing evaluate", async () => { diff --git a/tests/stealth_test.ts b/tests/stealth_test.ts new file mode 100644 index 0000000..511acf7 --- /dev/null +++ b/tests/stealth_test.ts @@ -0,0 +1,22 @@ +import { assert } from "https://deno.land/std@0.198.0/assert/assert.ts"; + +import { launch } from "../mod.ts"; + +/// + +Deno.test("Testing stealth", async () => { + // Launch browser + const browser = await launch(); + + // Open the webpage + const page = await browser.newPage("http://example.com"); + + // passing arguments to evaluate + const userAgent: string = await page.evaluate(() => { + return navigator.userAgent; + }); + assert(!userAgent.toLowerCase().includes("headless")); + + // Close browser + await browser.close(); +}); diff --git a/tests/wait_test.ts b/tests/wait_test.ts index 20b6683..bbb0a6d 100644 --- a/tests/wait_test.ts +++ b/tests/wait_test.ts @@ -1,4 +1,5 @@ import { assertSnapshot } from "https://deno.land/std@0.198.0/testing/snapshot.ts"; + import { launch } from "../mod.ts"; Deno.test("Wait for selector", async () => {