XORE21 commited on
Commit
ab05623
·
verified ·
1 Parent(s): 4970335

Create endpoints/cloudflare.js

Browse files
Files changed (1) hide show
  1. endpoints/cloudflare.js +33 -0
endpoints/cloudflare.js ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module.exports = async function (page, url) {
2
+ return new Promise(async (resolve, reject) => {
3
+ const timeout = setTimeout(() => reject(new Error("Timeout Cloudflare Bypass")), 30000);
4
+
5
+ try {
6
+ await page.goto(url, { waitUntil: "domcontentloaded" });
7
+
8
+ let clearanceCookie = null;
9
+
10
+ const checkInterval = setInterval(async () => {
11
+ const cookies = await page.cookies();
12
+ const cf = cookies.find(c => c.name === 'cf_clearance');
13
+
14
+ if (cf) {
15
+ clearanceCookie = cf.value;
16
+ clearInterval(checkInterval);
17
+ clearTimeout(timeout);
18
+
19
+ const userAgent = await page.evaluate(() => navigator.userAgent);
20
+ resolve({
21
+ cookie: clearanceCookie,
22
+ userAgent: userAgent,
23
+ cookies_full: cookies
24
+ });
25
+ }
26
+ }, 1000);
27
+
28
+ } catch (e) {
29
+ clearTimeout(timeout);
30
+ reject(e);
31
+ }
32
+ });
33
+ };