bexxcv 1.0.8 → 1.0.9

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.
package/dist/uam.js CHANGED
@@ -13,7 +13,24 @@ const CHALLENGE_TITLES = [
13
13
  ];
14
14
  const WATCHED = new WeakSet();
15
15
  const BUSY = new WeakSet();
16
- async function isChallenge(page) {
16
+ const MITIGATED = new WeakMap();
17
+ const TRACKED = new WeakSet();
18
+ export function trackMitigation(page) {
19
+ if (TRACKED.has(page))
20
+ return;
21
+ TRACKED.add(page);
22
+ page.on("response", (response) => {
23
+ const request = response.request();
24
+ if (!request.isNavigationRequest())
25
+ return;
26
+ if (request.frame() !== page.mainFrame())
27
+ return;
28
+ MITIGATED.set(page, response.headers()["cf-mitigated"] === "challenge");
29
+ });
30
+ }
31
+ export async function isChallenge(page) {
32
+ if (MITIGATED.get(page))
33
+ return true;
17
34
  const title = (await page.title().catch(() => "")).toLowerCase();
18
35
  return CHALLENGE_TITLES.some((t) => title.includes(t));
19
36
  }
@@ -26,7 +43,7 @@ async function cookieValue(page, name) {
26
43
  return null;
27
44
  }
28
45
  }
29
- async function humanActivity(page) {
46
+ export async function humanActivity(page, scale = 1) {
30
47
  let width = 1280;
31
48
  let height = 720;
32
49
  const view = page.viewportSize();
@@ -47,18 +64,19 @@ async function humanActivity(page) {
47
64
  width = 1280;
48
65
  }
49
66
  }
50
- const moves = Math.floor(between(4, 8));
67
+ const moves = Math.max(1, Math.floor(between(4, 8) * scale));
51
68
  for (let i = 0; i < moves; i++) {
52
69
  await page.mouse.move(between(width * 0.1, width * 0.9), between(height * 0.1, height * 0.9), { steps: Math.floor(between(6, 14)) });
53
70
  await sleep(between(250, 650));
54
71
  }
55
- const scrolls = Math.floor(between(2, 5));
72
+ const scrolls = Math.max(1, Math.floor(between(2, 5) * scale));
56
73
  for (let i = 0; i < scrolls; i++) {
57
74
  await page.mouse.wheel(0, between(60, 180));
58
75
  await sleep(between(400, 900));
59
76
  }
60
77
  }
61
78
  export async function waitForUam(page, options = {}) {
79
+ trackMitigation(page);
62
80
  const timeout = options.timeout ?? 30000;
63
81
  const start = Date.now();
64
82
  let challenged = false;
@@ -66,6 +84,13 @@ export async function waitForUam(page, options = {}) {
66
84
  while (Date.now() - start < timeout && !page.isClosed()) {
67
85
  if (await isChallenge(page)) {
68
86
  challenged = true;
87
+ if (options.assist) {
88
+ const acted = await options.assist(page).catch(() => false);
89
+ if (acted) {
90
+ await sleep(1500);
91
+ continue;
92
+ }
93
+ }
69
94
  try {
70
95
  await humanActivity(page);
71
96
  }
@@ -90,12 +115,12 @@ export async function waitForUam(page, options = {}) {
90
115
  return { challenged: false, bypassed: true, cookie };
91
116
  }
92
117
  try {
93
- await humanActivity(page);
118
+ await humanActivity(page, 0.4);
94
119
  }
95
120
  catch {
96
121
  await sleep(500);
97
122
  }
98
- await sleep(3000);
123
+ await sleep(2000);
99
124
  const second = await cookieValue(page, "cf_clearance");
100
125
  const retrySecond = await cookieValue(page, "cf_chl_rc_ni");
101
126
  if (second === cookie && !retrySecond) {
@@ -120,6 +145,7 @@ export function watchUam(page, options = {}) {
120
145
  if (WATCHED.has(page))
121
146
  return;
122
147
  WATCHED.add(page);
148
+ trackMitigation(page);
123
149
  const interval = options.interval ?? 1500;
124
150
  const timeout = options.timeout ?? 30000;
125
151
  const waitOnGoto = options.waitOnGoto ?? true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bexxcv",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {