Update endpoints/cloudflare.js
Browse files- endpoints/cloudflare.js +17 -15
endpoints/cloudflare.js
CHANGED
|
@@ -52,7 +52,6 @@ async function cloudflare(data, page) {
|
|
| 52 |
if (!isResolved) {
|
| 53 |
isResolved = true
|
| 54 |
clearTimeout(timeout)
|
| 55 |
-
|
| 56 |
resolve({
|
| 57 |
cf_clearance,
|
| 58 |
user_agent: userAgent,
|
|
@@ -65,27 +64,30 @@ async function cloudflare(data, page) {
|
|
| 65 |
} catch (_) {}
|
| 66 |
})
|
| 67 |
|
| 68 |
-
// 🧩 Tambahan:
|
| 69 |
if (data.cookies) {
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
if (typeof data.cookies === "string") {
|
| 72 |
-
|
|
|
|
| 73 |
const [name, value] = pair.trim().split("=")
|
| 74 |
-
|
| 75 |
-
}
|
| 76 |
-
await page.context().addCookies(cookies)
|
| 77 |
-
} else if (Array.isArray(data.cookies)) {
|
| 78 |
-
await page.context().addCookies(data.cookies)
|
| 79 |
} else if (typeof data.cookies === "object") {
|
| 80 |
-
const
|
| 81 |
-
name,
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
}
|
| 87 |
}
|
| 88 |
|
|
|
|
| 89 |
await page.goto(data.domain, { waitUntil: "domcontentloaded" })
|
| 90 |
userAgent = await page.evaluate(() => navigator.userAgent)
|
| 91 |
} catch (err) {
|
|
|
|
| 52 |
if (!isResolved) {
|
| 53 |
isResolved = true
|
| 54 |
clearTimeout(timeout)
|
|
|
|
| 55 |
resolve({
|
| 56 |
cf_clearance,
|
| 57 |
user_agent: userAgent,
|
|
|
|
| 64 |
} catch (_) {}
|
| 65 |
})
|
| 66 |
|
| 67 |
+
// 🧩 Tambahan: Set cookie manual (khusus Puppeteer)
|
| 68 |
if (data.cookies) {
|
| 69 |
+
const cookies = []
|
| 70 |
+
const domain = new URL(data.domain).hostname
|
| 71 |
+
|
| 72 |
if (typeof data.cookies === "string") {
|
| 73 |
+
// contoh: "captcha=recaptchav2; ci_session=xxx; cf_clearance=xxx"
|
| 74 |
+
for (const pair of data.cookies.split(";")) {
|
| 75 |
const [name, value] = pair.trim().split("=")
|
| 76 |
+
if (name && value) cookies.push({ name, value, domain })
|
| 77 |
+
}
|
|
|
|
|
|
|
|
|
|
| 78 |
} else if (typeof data.cookies === "object") {
|
| 79 |
+
for (const [name, value] of Object.entries(data.cookies)) {
|
| 80 |
+
cookies.push({ name, value, domain })
|
| 81 |
+
}
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
if (cookies.length) {
|
| 85 |
+
await page.setCookie(...cookies)
|
| 86 |
+
console.log("✅ Cookies telah diset:", cookies)
|
| 87 |
}
|
| 88 |
}
|
| 89 |
|
| 90 |
+
// Akses domain target
|
| 91 |
await page.goto(data.domain, { waitUntil: "domcontentloaded" })
|
| 92 |
userAgent = await page.evaluate(() => navigator.userAgent)
|
| 93 |
} catch (err) {
|