bexxcv 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ export interface HumanBox {
2
+ x: number;
3
+ y: number;
4
+ width: number;
5
+ height: number;
6
+ }
7
+ export interface HumanLocator {
8
+ scrollIntoViewIfNeeded(): Promise<void>;
9
+ boundingBox(): Promise<HumanBox | null>;
10
+ }
11
+ export interface HumanPage {
12
+ mouse: {
13
+ move(x: number, y: number): Promise<void>;
14
+ down(options?: {
15
+ button?: "left" | "right" | "middle";
16
+ }): Promise<void>;
17
+ up(options?: {
18
+ button?: "left" | "right" | "middle";
19
+ }): Promise<void>;
20
+ wheel(deltaX: number, deltaY: number): Promise<void>;
21
+ };
22
+ keyboard: {
23
+ type(text: string): Promise<void>;
24
+ press(key: string): Promise<void>;
25
+ };
26
+ locator(selector: string): HumanLocator;
27
+ viewportSize(): {
28
+ width: number;
29
+ height: number;
30
+ } | null;
31
+ evaluate(pageFunction: any): Promise<any>;
32
+ }
33
+ export interface HumanOptions {
34
+ speed?: number;
35
+ nativeCursor?: boolean;
36
+ typoRate?: number;
37
+ }
38
+ export interface HumanClickOptions {
39
+ button?: "left" | "right" | "middle";
40
+ }
41
+ type Point = {
42
+ x: number;
43
+ y: number;
44
+ };
45
+ export declare class Human {
46
+ private readonly page;
47
+ private readonly speed;
48
+ private readonly nativeCursor;
49
+ private readonly typoRate;
50
+ private x;
51
+ private y;
52
+ private placed;
53
+ constructor(page: HumanPage, options?: HumanOptions);
54
+ pause(min?: number, max?: number): Promise<void>;
55
+ moveTo(x: number, y: number): Promise<void>;
56
+ click(target: string | Point, options?: HumanClickOptions): Promise<void>;
57
+ type(target: string | null, text: string): Promise<void>;
58
+ scroll(deltaY: number): Promise<void>;
59
+ scrollTo(selector: string): Promise<void>;
60
+ idle(ms?: number): Promise<void>;
61
+ private keyDelay;
62
+ private ensurePlaced;
63
+ private viewportHeight;
64
+ private pointInside;
65
+ private curve;
66
+ }
67
+ export declare function createHuman(page: HumanPage, options?: HumanOptions): Human;
68
+ export {};
package/dist/human.js ADDED
@@ -0,0 +1,249 @@
1
+ const KEY_ROWS = ["qwertyuiop", "asdfghjkl", "zxcvbnm"];
2
+ function rand() {
3
+ const buf = new Uint32Array(1);
4
+ crypto.getRandomValues(buf);
5
+ return buf[0] / 4294967296;
6
+ }
7
+ function between(min, max) {
8
+ return min + rand() * (max - min);
9
+ }
10
+ function gauss(mean, sd) {
11
+ const u = 1 - rand();
12
+ const v = rand();
13
+ return mean + sd * Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
14
+ }
15
+ function logNormal(median, sigma) {
16
+ return median * Math.exp(gauss(0, sigma));
17
+ }
18
+ function clamp(value, min, max) {
19
+ return Math.min(max, Math.max(min, value));
20
+ }
21
+ function sleep(ms) {
22
+ return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
23
+ }
24
+ function neighborKey(ch) {
25
+ const lower = ch.toLowerCase();
26
+ const candidates = [];
27
+ for (let r = 0; r < KEY_ROWS.length; r++) {
28
+ const idx = KEY_ROWS[r].indexOf(lower);
29
+ if (idx === -1)
30
+ continue;
31
+ const row = KEY_ROWS[r];
32
+ if (idx > 0)
33
+ candidates.push(row[idx - 1]);
34
+ if (idx < row.length - 1)
35
+ candidates.push(row[idx + 1]);
36
+ for (const other of [r - 1, r + 1]) {
37
+ const otherRow = KEY_ROWS[other];
38
+ if (otherRow && otherRow[idx])
39
+ candidates.push(otherRow[idx]);
40
+ }
41
+ break;
42
+ }
43
+ if (candidates.length === 0)
44
+ return null;
45
+ const pick = candidates[Math.floor(rand() * candidates.length)];
46
+ return ch === lower ? pick : pick.toUpperCase();
47
+ }
48
+ export class Human {
49
+ page;
50
+ speed;
51
+ nativeCursor;
52
+ typoRate;
53
+ x;
54
+ y;
55
+ placed = false;
56
+ constructor(page, options = {}) {
57
+ this.page = page;
58
+ this.speed = clamp(options.speed ?? 1, 0.2, 20);
59
+ this.nativeCursor = options.nativeCursor ?? true;
60
+ this.typoRate = clamp(options.typoRate ?? 0.015, 0, 0.2);
61
+ const view = page.viewportSize() ?? { width: 1280, height: 720 };
62
+ this.x = between(view.width * 0.25, view.width * 0.75);
63
+ this.y = between(view.height * 0.25, view.height * 0.75);
64
+ }
65
+ async pause(min = 350, max = 1400) {
66
+ const target = clamp(logNormal(Math.sqrt(min * max), 0.35), min, max);
67
+ await sleep(target / this.speed);
68
+ }
69
+ async moveTo(x, y) {
70
+ await this.ensurePlaced();
71
+ if (this.nativeCursor) {
72
+ await this.page.mouse.move(x, y);
73
+ this.x = x;
74
+ this.y = y;
75
+ return;
76
+ }
77
+ const dx = x - this.x;
78
+ const dy = y - this.y;
79
+ const dist = Math.hypot(dx, dy);
80
+ if (dist < 2) {
81
+ await this.page.mouse.move(x, y);
82
+ this.x = x;
83
+ this.y = y;
84
+ return;
85
+ }
86
+ if (dist > 300 && rand() < 0.35) {
87
+ const over = between(6, 18);
88
+ await this.curve(x + (dx / dist) * over, y + (dy / dist) * over);
89
+ }
90
+ await this.curve(x, y);
91
+ }
92
+ async click(target, options = {}) {
93
+ const point = typeof target === "string" ? await this.pointInside(target) : target;
94
+ await this.moveTo(point.x, point.y);
95
+ await sleep(between(50, 200) / this.speed);
96
+ await this.page.mouse.down({ button: options.button });
97
+ await sleep(between(45, 130));
98
+ await this.page.mouse.up({ button: options.button });
99
+ }
100
+ async type(target, text) {
101
+ if (target) {
102
+ await this.click(target);
103
+ await sleep(between(120, 400) / this.speed);
104
+ }
105
+ let untilBreak = Math.round(between(6, 18));
106
+ for (const ch of Array.from(text)) {
107
+ if (this.typoRate > 0 && /[a-z]/i.test(ch) && rand() < this.typoRate) {
108
+ const wrong = neighborKey(ch);
109
+ if (wrong) {
110
+ await this.page.keyboard.type(wrong);
111
+ await sleep(this.keyDelay() + between(120, 380) / this.speed);
112
+ await this.page.keyboard.press("Backspace");
113
+ await sleep(between(60, 200) / this.speed);
114
+ }
115
+ }
116
+ await this.page.keyboard.type(ch);
117
+ let wait = this.keyDelay();
118
+ if (ch === " ")
119
+ wait += between(30, 140) / this.speed;
120
+ else if (/[.,;:!?]/.test(ch))
121
+ wait += between(80, 260) / this.speed;
122
+ untilBreak--;
123
+ if (untilBreak <= 0) {
124
+ wait += between(200, 650) / this.speed;
125
+ untilBreak = Math.round(between(6, 18));
126
+ }
127
+ await sleep(wait);
128
+ }
129
+ }
130
+ async scroll(deltaY) {
131
+ const dir = Math.sign(deltaY);
132
+ if (!dir)
133
+ return;
134
+ await this.ensurePlaced();
135
+ let remaining = Math.abs(deltaY);
136
+ while (remaining > 0) {
137
+ const chunk = Math.min(remaining, Math.round(between(60, 170)));
138
+ await this.page.mouse.wheel(0, dir * chunk);
139
+ remaining -= chunk;
140
+ let wait = clamp(logNormal(38, 0.5), 12, 160) / this.speed;
141
+ if (rand() < 0.06)
142
+ wait += between(250, 900) / this.speed;
143
+ await sleep(wait);
144
+ }
145
+ }
146
+ async scrollTo(selector) {
147
+ const box = await this.page.locator(selector).boundingBox();
148
+ if (!box)
149
+ throw new Error(`Element not found or not visible: ${selector}`);
150
+ const height = await this.viewportHeight();
151
+ const delta = box.y + box.height / 2 - height / 2;
152
+ if (Math.abs(delta) > 40) {
153
+ await this.scroll(delta + between(-60, 60));
154
+ }
155
+ }
156
+ async idle(ms = 1500) {
157
+ await this.ensurePlaced();
158
+ const end = Date.now() + ms / this.speed;
159
+ while (Date.now() < end) {
160
+ this.x = Math.max(0, this.x + gauss(0, 10));
161
+ this.y = Math.max(0, this.y + gauss(0, 8));
162
+ await this.page.mouse.move(this.x, this.y);
163
+ await sleep(between(120, 500) / this.speed);
164
+ }
165
+ }
166
+ keyDelay() {
167
+ return clamp(logNormal(105, 0.4), 35, 420) / this.speed;
168
+ }
169
+ async ensurePlaced() {
170
+ if (this.placed)
171
+ return;
172
+ this.placed = true;
173
+ await this.page.mouse.move(this.x, this.y);
174
+ }
175
+ async viewportHeight() {
176
+ const view = this.page.viewportSize();
177
+ if (view)
178
+ return view.height;
179
+ try {
180
+ const value = await this.page.evaluate("window.innerHeight");
181
+ if (typeof value === "number" && value > 0)
182
+ return value;
183
+ }
184
+ catch {
185
+ return 720;
186
+ }
187
+ return 720;
188
+ }
189
+ async pointInside(selector) {
190
+ const locator = this.page.locator(selector);
191
+ await locator.scrollIntoViewIfNeeded();
192
+ const box = await locator.boundingBox();
193
+ if (!box)
194
+ throw new Error(`Element not found or not visible: ${selector}`);
195
+ return {
196
+ x: box.x + box.width * clamp(gauss(0.5, 0.15), 0.12, 0.88),
197
+ y: box.y + box.height * clamp(gauss(0.5, 0.15), 0.12, 0.88),
198
+ };
199
+ }
200
+ async curve(tx, ty) {
201
+ const sx = this.x;
202
+ const sy = this.y;
203
+ const dx = tx - sx;
204
+ const dy = ty - sy;
205
+ const dist = Math.hypot(dx, dy);
206
+ if (dist < 1) {
207
+ await this.page.mouse.move(tx, ty);
208
+ this.x = tx;
209
+ this.y = ty;
210
+ return;
211
+ }
212
+ const nx = -dy / dist;
213
+ const ny = dx / dist;
214
+ const side = rand() < 0.5 ? -1 : 1;
215
+ const spread = dist * between(0.05, 0.25) * side;
216
+ const c1 = {
217
+ x: sx + dx * 0.3 + nx * spread,
218
+ y: sy + dy * 0.3 + ny * spread,
219
+ };
220
+ const c2 = {
221
+ x: sx + dx * 0.7 + nx * spread * between(0.3, 1),
222
+ y: sy + dy * 0.7 + ny * spread * between(0.3, 1),
223
+ };
224
+ const steps = clamp(Math.round(dist / between(7, 14)), 6, 90);
225
+ const duration = clamp(logNormal(180 + dist * 0.9, 0.2), 120, 1400) / this.speed;
226
+ for (let i = 1; i <= steps; i++) {
227
+ const raw = i / steps;
228
+ const t = raw * raw * (3 - 2 * raw);
229
+ const u = 1 - t;
230
+ let px = u * u * u * sx + 3 * u * u * t * c1.x + 3 * u * t * t * c2.x + t * t * t * tx;
231
+ let py = u * u * u * sy + 3 * u * u * t * c1.y + 3 * u * t * t * c2.y + t * t * t * ty;
232
+ if (i < steps) {
233
+ px += gauss(0, 0.5);
234
+ py += gauss(0, 0.5);
235
+ }
236
+ else {
237
+ px = tx;
238
+ py = ty;
239
+ }
240
+ await this.page.mouse.move(Math.max(0, px), Math.max(0, py));
241
+ await sleep((duration / steps) * between(0.6, 1.4));
242
+ }
243
+ this.x = tx;
244
+ this.y = ty;
245
+ }
246
+ }
247
+ export function createHuman(page, options = {}) {
248
+ return new Human(page, options);
249
+ }
package/dist/index.d.ts CHANGED
@@ -4,3 +4,6 @@ export { type LaunchOptions, launchOptions } from "./utils.js";
4
4
  export { VirtualDisplay } from "./virtdisplay.js";
5
5
  export { needsXvfb, startXvfb, withXvfb } from "./xvfb.js";
6
6
  export { checkSelfUpdate, applySelfUpdate, type SelfUpdateInfo } from "./selfupdate.js";
7
+ export { createHuman, Human, type HumanClickOptions, type HumanOptions, type HumanPage, } from "./human.js";
8
+ export { attachTurnstile, watchTurnstile, type TurnstileOptions, } from "./turnstile.js";
9
+ export { attachUam, waitForUam, watchUam, type UamOptions, type UamResult } from "./uam.js";
package/dist/index.js CHANGED
@@ -4,3 +4,6 @@ export { launchOptions } from "./utils.js";
4
4
  export { VirtualDisplay } from "./virtdisplay.js";
5
5
  export { needsXvfb, startXvfb, withXvfb } from "./xvfb.js";
6
6
  export { checkSelfUpdate, applySelfUpdate } from "./selfupdate.js";
7
+ export { createHuman, Human, } from "./human.js";
8
+ export { attachTurnstile, watchTurnstile, } from "./turnstile.js";
9
+ export { attachUam, waitForUam, watchUam } from "./uam.js";
@@ -0,0 +1,2 @@
1
+ import type { Browser, BrowserContext, Page } from "playwright-core";
2
+ export declare function onEachPage<T extends Browser | BrowserContext>(target: T, handler: (page: Page) => void): T;
@@ -0,0 +1,25 @@
1
+ export function onEachPage(target, handler) {
2
+ const seen = new WeakSet();
3
+ const watchContext = (context) => {
4
+ if (seen.has(context))
5
+ return;
6
+ seen.add(context);
7
+ for (const page of context.pages())
8
+ handler(page);
9
+ context.on("page", (page) => handler(page));
10
+ };
11
+ if (typeof target.newContext !== "function") {
12
+ watchContext(target);
13
+ return target;
14
+ }
15
+ const browser = target;
16
+ for (const context of browser.contexts())
17
+ watchContext(context);
18
+ const originalNewContext = browser.newContext.bind(browser);
19
+ browser.newContext = async (...args) => {
20
+ const context = await originalNewContext(...args);
21
+ watchContext(context);
22
+ return context;
23
+ };
24
+ return target;
25
+ }
@@ -1,8 +1,12 @@
1
1
  import { type Browser, type BrowserContext, type BrowserType } from "playwright-core";
2
2
  import { type LaunchOptions } from "./utils.js";
3
+ import { type TurnstileOptions } from "./turnstile.js";
4
+ import { type UamOptions } from "./uam.js";
3
5
  export interface BexxcvOptions extends LaunchOptions {
4
6
  user_data_dir?: string;
5
7
  auto_xvfb?: boolean;
8
+ turnstile?: boolean | TurnstileOptions;
9
+ uam?: boolean | UamOptions;
6
10
  }
7
11
  export declare function Bexxcv<UserDataDir extends string | undefined = undefined, ReturnType = UserDataDir extends string ? BrowserContext : Browser>(launch_options?: BexxcvOptions & {
8
12
  user_data_dir?: UserDataDir;
package/dist/sync_api.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { firefox, } from "playwright-core";
2
2
  import { attachNoViewportDefault, launchOptions, spoofsWindowDimensions, syncAttachVD, } from "./utils.js";
3
+ import { attachTurnstile } from "./turnstile.js";
4
+ import { attachUam } from "./uam.js";
3
5
  import { VirtualDisplay } from "./virtdisplay.js";
4
6
  import { needsXvfb } from "./xvfb.js";
5
7
  export async function Bexxcv(launch_options = {}) {
6
- const { headless, user_data_dir, auto_xvfb = true, ...opts } = launch_options;
8
+ const { headless, user_data_dir, auto_xvfb = true, turnstile = false, uam = false, ...opts } = launch_options;
7
9
  const needsDisplay = auto_xvfb && needsXvfb();
8
10
  const effectiveHeadless = (() => {
9
11
  if (headless === "virtual")
@@ -14,7 +16,14 @@ export async function Bexxcv(launch_options = {}) {
14
16
  return "virtual";
15
17
  return headless ?? false;
16
18
  })();
17
- return NewBrowser(firefox, effectiveHeadless, {}, user_data_dir ?? false, false, opts);
19
+ const launched = await NewBrowser(firefox, effectiveHeadless, {}, user_data_dir ?? false, false, opts);
20
+ if (turnstile) {
21
+ attachTurnstile(launched, turnstile === true ? {} : turnstile);
22
+ }
23
+ if (uam) {
24
+ attachUam(launched, uam === true ? {} : uam);
25
+ }
26
+ return launched;
18
27
  }
19
28
  export const Camoufox = Bexxcv;
20
29
  export async function NewBrowser(playwright, headless = false, fromOptions = {}, userDataDir = false, debug = false, launch_options = {}) {
@@ -0,0 +1,7 @@
1
+ import type { Browser, BrowserContext, Page } from "playwright-core";
2
+ export interface TurnstileOptions {
3
+ interval?: number;
4
+ retryAfter?: number;
5
+ }
6
+ export declare function watchTurnstile(page: Page, options?: TurnstileOptions): void;
7
+ export declare function attachTurnstile<T extends Browser | BrowserContext>(target: T, options?: TurnstileOptions): T;
@@ -0,0 +1,99 @@
1
+ import { onEachPage } from "./pagehooks.js";
2
+ const WATCHED = new WeakSet();
3
+ function sleep(ms) {
4
+ return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
5
+ }
6
+ function between(min, max) {
7
+ return min + Math.random() * (max - min);
8
+ }
9
+ async function findWidgets(page) {
10
+ return page.evaluate(() => {
11
+ const out = [];
12
+ const seen = new Set();
13
+ const push = (el, solved) => {
14
+ let rect = el.getBoundingClientRect();
15
+ if (rect.width < 10 || rect.height < 10)
16
+ return;
17
+ if (!solved && (rect.top < 0 || rect.bottom > window.innerHeight)) {
18
+ el.scrollIntoView({ block: "center", behavior: "instant" });
19
+ rect = el.getBoundingClientRect();
20
+ }
21
+ const key = `${Math.round(rect.x + window.scrollX)}:${Math.round(rect.y + window.scrollY)}:${Math.round(rect.width)}`;
22
+ if (seen.has(key))
23
+ return;
24
+ seen.add(key);
25
+ out.push({ x: rect.x, y: rect.y, w: rect.width, h: rect.height, solved, key });
26
+ };
27
+ for (const input of Array.from(document.querySelectorAll('[name="cf-turnstile-response"]'))) {
28
+ const parent = input.parentElement;
29
+ if (!parent)
30
+ continue;
31
+ push(parent, !!input.value && input.value.length > 10);
32
+ }
33
+ if (out.length === 0) {
34
+ for (const strict of [true, false]) {
35
+ for (const div of Array.from(document.querySelectorAll("div"))) {
36
+ const rect = div.getBoundingClientRect();
37
+ if (rect.width <= 290 || rect.width > 310 || div.querySelector("*"))
38
+ continue;
39
+ if (strict) {
40
+ const css = window.getComputedStyle(div);
41
+ if (css.margin !== "0px" || css.padding !== "0px")
42
+ continue;
43
+ }
44
+ push(div, false);
45
+ }
46
+ if (out.length > 0)
47
+ break;
48
+ }
49
+ }
50
+ return out;
51
+ });
52
+ }
53
+ async function clickAt(page, x, y) {
54
+ await page.mouse.move(x + between(-60, 60), y + between(-40, 40), { steps: 4 });
55
+ await sleep(between(60, 160));
56
+ await page.mouse.move(x, y, { steps: Math.floor(between(8, 16)) });
57
+ await sleep(between(60, 140));
58
+ await page.mouse.down();
59
+ await sleep(between(60, 120));
60
+ await page.mouse.up();
61
+ }
62
+ export function watchTurnstile(page, options = {}) {
63
+ if (WATCHED.has(page))
64
+ return;
65
+ WATCHED.add(page);
66
+ const interval = options.interval ?? 1000;
67
+ const retryAfter = options.retryAfter ?? 8000;
68
+ const clicked = new Map();
69
+ let active = true;
70
+ page.on("close", () => {
71
+ active = false;
72
+ });
73
+ const loop = async () => {
74
+ while (active && !page.isClosed()) {
75
+ try {
76
+ const widgets = await findWidgets(page);
77
+ for (const widget of widgets) {
78
+ if (widget.solved)
79
+ continue;
80
+ const last = clicked.get(widget.key) ?? 0;
81
+ if (Date.now() - last < retryAfter)
82
+ continue;
83
+ clicked.set(widget.key, Date.now());
84
+ const x = widget.x + Math.min(30, widget.w / 2) + between(-4, 4);
85
+ const y = widget.y + widget.h / 2 + between(-4, 4);
86
+ await clickAt(page, x, y);
87
+ }
88
+ }
89
+ catch {
90
+ await sleep(500);
91
+ }
92
+ await sleep(interval);
93
+ }
94
+ };
95
+ void loop();
96
+ }
97
+ export function attachTurnstile(target, options = {}) {
98
+ return onEachPage(target, (page) => watchTurnstile(page, options));
99
+ }
package/dist/uam.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { Browser, BrowserContext, Page } from "playwright-core";
2
+ export interface UamOptions {
3
+ timeout?: number;
4
+ interval?: number;
5
+ waitOnGoto?: boolean;
6
+ }
7
+ export interface UamResult {
8
+ challenged: boolean;
9
+ bypassed: boolean;
10
+ cookie: string | null;
11
+ }
12
+ export declare function waitForUam(page: Page, options?: UamOptions): Promise<UamResult>;
13
+ export declare function watchUam(page: Page, options?: UamOptions): void;
14
+ export declare function attachUam<T extends Browser | BrowserContext>(target: T, options?: UamOptions): T;
package/dist/uam.js ADDED
@@ -0,0 +1,164 @@
1
+ import { onEachPage } from "./pagehooks.js";
2
+ const CHALLENGE_TITLES = [
3
+ "just a moment",
4
+ "tunggu sebentar",
5
+ "attention required",
6
+ "security check",
7
+ "un instant",
8
+ "einen moment",
9
+ "один момент",
10
+ "um momento",
11
+ "un momento",
12
+ ];
13
+ const WATCHED = new WeakSet();
14
+ const BUSY = new WeakSet();
15
+ function sleep(ms) {
16
+ return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
17
+ }
18
+ function between(min, max) {
19
+ return min + Math.random() * (max - min);
20
+ }
21
+ async function isChallenge(page) {
22
+ const title = (await page.title().catch(() => "")).toLowerCase();
23
+ return CHALLENGE_TITLES.some((t) => title.includes(t));
24
+ }
25
+ async function cookieValue(page, name) {
26
+ try {
27
+ const cookies = await page.context().cookies(page.url());
28
+ return cookies.find((c) => c.name === name)?.value ?? null;
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ }
34
+ async function humanActivity(page) {
35
+ let width = 1280;
36
+ let height = 720;
37
+ const view = page.viewportSize();
38
+ if (view) {
39
+ width = view.width;
40
+ height = view.height;
41
+ }
42
+ else {
43
+ try {
44
+ const size = await page.evaluate(() => ({
45
+ w: window.innerWidth,
46
+ h: window.innerHeight,
47
+ }));
48
+ width = size.w;
49
+ height = size.h;
50
+ }
51
+ catch {
52
+ width = 1280;
53
+ }
54
+ }
55
+ const moves = Math.floor(between(4, 8));
56
+ for (let i = 0; i < moves; i++) {
57
+ await page.mouse.move(between(width * 0.1, width * 0.9), between(height * 0.1, height * 0.9), { steps: Math.floor(between(6, 14)) });
58
+ await sleep(between(250, 650));
59
+ }
60
+ const scrolls = Math.floor(between(2, 5));
61
+ for (let i = 0; i < scrolls; i++) {
62
+ await page.mouse.wheel(0, between(60, 180));
63
+ await sleep(between(400, 900));
64
+ }
65
+ }
66
+ export async function waitForUam(page, options = {}) {
67
+ const timeout = options.timeout ?? 30000;
68
+ const start = Date.now();
69
+ let challenged = false;
70
+ let missing = 0;
71
+ while (Date.now() - start < timeout && !page.isClosed()) {
72
+ if (await isChallenge(page)) {
73
+ challenged = true;
74
+ try {
75
+ await humanActivity(page);
76
+ }
77
+ catch {
78
+ await sleep(500);
79
+ }
80
+ await sleep(1500);
81
+ continue;
82
+ }
83
+ const cookie = await cookieValue(page, "cf_clearance");
84
+ if (!cookie) {
85
+ if (!challenged)
86
+ return { challenged: false, bypassed: false, cookie: null };
87
+ missing++;
88
+ if (missing > 3)
89
+ return { challenged: true, bypassed: true, cookie: null };
90
+ await sleep(1000);
91
+ continue;
92
+ }
93
+ const retry = await cookieValue(page, "cf_chl_rc_ni");
94
+ if (!challenged && !retry) {
95
+ return { challenged: false, bypassed: true, cookie };
96
+ }
97
+ try {
98
+ await humanActivity(page);
99
+ }
100
+ catch {
101
+ await sleep(500);
102
+ }
103
+ await sleep(3000);
104
+ const second = await cookieValue(page, "cf_clearance");
105
+ const retrySecond = await cookieValue(page, "cf_chl_rc_ni");
106
+ if (second === cookie && !retrySecond) {
107
+ return { challenged, bypassed: true, cookie: second };
108
+ }
109
+ await sleep(1500);
110
+ }
111
+ return { challenged, bypassed: false, cookie: null };
112
+ }
113
+ async function runWait(page, options) {
114
+ if (BUSY.has(page))
115
+ return undefined;
116
+ BUSY.add(page);
117
+ try {
118
+ return await waitForUam(page, options);
119
+ }
120
+ finally {
121
+ BUSY.delete(page);
122
+ }
123
+ }
124
+ export function watchUam(page, options = {}) {
125
+ if (WATCHED.has(page))
126
+ return;
127
+ WATCHED.add(page);
128
+ const interval = options.interval ?? 1500;
129
+ const timeout = options.timeout ?? 30000;
130
+ const waitOnGoto = options.waitOnGoto ?? true;
131
+ if (waitOnGoto) {
132
+ const originalGoto = page.goto.bind(page);
133
+ page.goto = (async (...args) => {
134
+ const response = await originalGoto(...args);
135
+ const began = Date.now();
136
+ while (BUSY.has(page) && Date.now() - began < timeout) {
137
+ await sleep(200);
138
+ }
139
+ await runWait(page, options).catch(() => undefined);
140
+ return response;
141
+ });
142
+ }
143
+ let active = true;
144
+ page.on("close", () => {
145
+ active = false;
146
+ });
147
+ const loop = async () => {
148
+ while (active && !page.isClosed()) {
149
+ try {
150
+ if (!BUSY.has(page) && (await isChallenge(page))) {
151
+ await runWait(page, options);
152
+ }
153
+ }
154
+ catch {
155
+ await sleep(500);
156
+ }
157
+ await sleep(interval);
158
+ }
159
+ };
160
+ void loop();
161
+ }
162
+ export function attachUam(target, options = {}) {
163
+ return onEachPage(target, (page) => watchUam(page, options));
164
+ }
package/dist/utils.js CHANGED
@@ -288,6 +288,22 @@ export function syncAttachVD(browser, virtualDisplay) {
288
288
  browser._virtualDisplay = virtualDisplay;
289
289
  return browser;
290
290
  }
291
+ const FAST_STARTUP_PREFS = {
292
+ "app.update.auto": false,
293
+ "app.update.enabled": false,
294
+ "browser.shell.checkDefaultBrowser": false,
295
+ "browser.aboutwelcome.enabled": false,
296
+ "browser.search.update": false,
297
+ "browser.startup.homepage_override.mstone": "ignore",
298
+ "datareporting.healthreport.uploadEnabled": false,
299
+ "datareporting.policy.dataSubmissionEnabled": false,
300
+ "extensions.update.enabled": false,
301
+ "messaging-system.rsexperimentloader.enabled": false,
302
+ "network.captive-portal-service.enabled": false,
303
+ "toolkit.telemetry.archive.enabled": false,
304
+ "toolkit.telemetry.enabled": false,
305
+ "toolkit.telemetry.unified": false,
306
+ };
291
307
  function getProxyUrl(proxy) {
292
308
  if (!proxy)
293
309
  return null;
@@ -346,6 +362,9 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
346
362
  if (!operatingSystems && webgl_config) {
347
363
  throw new Error("OS must be set when using webgl_config");
348
364
  }
365
+ const proxyUrl = getProxyUrl(proxy);
366
+ const ipTask = geoip && typeof geoip !== "string" ? publicIP(proxyUrl?.href) : null;
367
+ ipTask?.catch(() => { });
349
368
  if (!executable_path &&
350
369
  !getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
351
370
  await ensureCamoufoxInstalled();
@@ -403,11 +422,10 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
403
422
  else {
404
423
  updateFonts(config, targetOS);
405
424
  }
406
- const proxyUrl = getProxyUrl(proxy);
407
425
  if (geoip) {
408
426
  geoipAllowed();
409
427
  if (typeof geoip !== "string") {
410
- geoip = await publicIP(proxyUrl?.href);
428
+ geoip = await ipTask;
411
429
  }
412
430
  if (!block_webrtc) {
413
431
  if (validIPv4(geoip)) {
@@ -498,7 +516,7 @@ export async function launchOptions({ config, os, block_images, block_webrtc, bl
498
516
  executablePath: executable_path,
499
517
  args: args,
500
518
  env: env_vars,
501
- firefoxUserPrefs: firefox_user_prefs,
519
+ firefoxUserPrefs: { ...FAST_STARTUP_PREFS, ...firefox_user_prefs },
502
520
  proxy: proxyUrl
503
521
  ? {
504
522
  server: proxyUrl.origin,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bexxcv",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {