rezaharis commited on
Commit
3e6915a
·
verified ·
1 Parent(s): ba1bc76

Update endpoints/cloudflare-cookies.js

Browse files
Files changed (1) hide show
  1. endpoints/cloudflare-cookies.js +4 -4
endpoints/cloudflare-cookies.js CHANGED
@@ -7,16 +7,16 @@ async function cloudflareCookies(page, originalCookiesString, cl, opts = {}) {
7
  const wait = ms => new Promise(res => setTimeout(res, ms));
8
 
9
  while (Date.now() - start < timeout) {
10
- const content = await page.content();
11
  const lower = content.toLowerCase();
12
 
13
  if (lower.includes('just a moment') || lower.includes('turnstile')) {
14
- await page.waitForNavigation({ waitUntil: 'networkidle', timeout: 30000 }).catch(() => {});
15
  await wait(1000);
16
  continue;
17
  }
18
 
19
- const cookies = await page.cookies();
20
  newClearanceCookie = cookies.find(c => c.name === 'cf_clearance');
21
  if (newClearanceCookie) break;
22
 
@@ -25,7 +25,7 @@ async function cloudflareCookies(page, originalCookiesString, cl, opts = {}) {
25
 
26
  clearTimeout(cl);
27
 
28
- const finalCookies = await page.cookies();
29
  const finalUrl = page.url();
30
  const userAgent = await page.evaluate(() => navigator.userAgent);
31
 
 
7
  const wait = ms => new Promise(res => setTimeout(res, ms));
8
 
9
  while (Date.now() - start < timeout) {
10
+ const content = await page.content().catch(() => "");
11
  const lower = content.toLowerCase();
12
 
13
  if (lower.includes('just a moment') || lower.includes('turnstile')) {
14
+ await page.waitForLoadState('networkidle', { timeout: 30000 }).catch(() => {});
15
  await wait(1000);
16
  continue;
17
  }
18
 
19
+ const cookies = await page.context().cookies().catch(() => []);
20
  newClearanceCookie = cookies.find(c => c.name === 'cf_clearance');
21
  if (newClearanceCookie) break;
22
 
 
25
 
26
  clearTimeout(cl);
27
 
28
+ const finalCookies = await page.context().cookies().catch(() => []);
29
  const finalUrl = page.url();
30
  const userAgent = await page.evaluate(() => navigator.userAgent);
31