Skip to content

Commit

Permalink
feat: user agent stealth
Browse files Browse the repository at this point in the history
  • Loading branch information
lino-levan committed Aug 22, 2023
1 parent 4c30291 commit 10ddd22
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
]);
Expand Down
1 change: 1 addition & 0 deletions tests/evaluate_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/assert_equals.ts";

import { launch } from "../mod.ts";

Deno.test("Testing evaluate", async () => {
Expand Down
22 changes: 22 additions & 0 deletions tests/stealth_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { assert } from "https://deno.land/[email protected]/assert/assert.ts";

import { launch } from "../mod.ts";

/// <reference lib="dom" />

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();
});
1 change: 1 addition & 0 deletions tests/wait_test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assertSnapshot } from "https://deno.land/[email protected]/testing/snapshot.ts";

import { launch } from "../mod.ts";

Deno.test("Wait for selector", async () => {
Expand Down

0 comments on commit 10ddd22

Please sign in to comment.