2 Commits

Author SHA1 Message Date
estebanthi
24b0ddf666 Add optional full cookie response
All checks were successful
CI / release (push) Successful in 1m38s
2026-02-04 10:01:50 +01:00
estebanthi
3c73bccb81 Add optional HTML response for IUAM
All checks were successful
CI / release (push) Successful in 2m44s
2026-02-04 09:36:52 +01:00
3 changed files with 61 additions and 8 deletions

View File

@@ -76,7 +76,9 @@ Bypass Cloudflare protection and get cookies/tokens.
{
"mode": "iuam",
"domain": "https://olamovies.watch/generate",
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"include_html": true,
"include_cookies": true
}
```
@@ -84,6 +86,8 @@ Bypass Cloudflare protection and get cookies/tokens.
- **`mode`** (required): `"iuam"` or `"turnstile"`
- **`domain`** (required): Target website URL
- **`user_agent`** (optional): User-Agent to use for the browser session
- **`include_html`** (optional): `true` to include the final page HTML in IUAM responses
- **`include_cookies`** (optional): `true` to include all cookies in IUAM responses
- **`proxy`** (optional): Proxy configuration object
#### Response (Success)
@@ -91,7 +95,11 @@ Bypass Cloudflare protection and get cookies/tokens.
{
"cf_clearance": "eNm9UOgqoNDTP.fmAK9JfvirEmLVpmd.ZWIfdqQxuTc-1758610092-1.2-2NwZwW6nK23HrAH71MtvOek9vCiiS7pUBGIPtra_gSBxYxY2csa6hW0j7i...",
"user_agent": "Mozilla/5.0...",
"elapsed_time": 3.05
"elapsed_time": 3.05,
"html": "<!DOCTYPE html><html>...</html>",
"cookies": [
{ "name": "cf_clearance", "value": "...", "domain": ".example.com" }
]
}
```

View File

@@ -1,3 +1,25 @@
async function ensurePageLoaded(page, url) {
try {
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 10000 })
} catch (_) {}
}
async function getPageHtml(page) {
try {
return await page.content()
} catch (_) {
return null
}
}
async function getPageCookies(page, url) {
try {
return await page.cookies(url)
} catch (_) {
return null
}
}
async function cloudflare(data, page) {
return new Promise(async (resolve, reject) => {
if (!data.domain) return reject(new Error("Missing domain parameter"))
@@ -10,11 +32,14 @@ async function cloudflare(data, page) {
if (!isResolved) {
isResolved = true
const elapsedTime = (Date.now() - startTime) / 1000
resolve({
const response = {
cf_clearance: null,
user_agent: userAgent,
elapsed_time: elapsedTime,
})
}
if (data.include_html) response.html = null
if (data.include_cookies) response.cookies = null
resolve(response)
}
}, 20000)
@@ -52,11 +77,25 @@ async function cloudflare(data, page) {
isResolved = true
clearTimeout(cl)
resolve({
const response = {
cf_clearance,
user_agent: userAgent,
elapsed_time: elapsedTime,
})
}
if (data.include_html || data.include_cookies) {
await ensurePageLoaded(page, data.domain)
}
if (data.include_html) {
response.html = await getPageHtml(page)
}
if (data.include_cookies) {
response.cookies = await getPageCookies(page, data.domain)
}
resolve(response)
}
}
}

View File

@@ -103,6 +103,12 @@ app.post('/cloudflare', async (req, res) => {
if (data.user_agent && typeof data.user_agent !== 'string') {
return res.status(400).json({ message: 'Bad Request: invalid user_agent' })
}
if (typeof data.include_html !== 'undefined' && typeof data.include_html !== 'boolean') {
return res.status(400).json({ message: 'Bad Request: invalid include_html' })
}
if (typeof data.include_cookies !== 'undefined' && typeof data.include_cookies !== 'boolean') {
return res.status(400).json({ message: 'Bad Request: invalid include_cookies' })
}
if (authToken && data.authToken !== authToken) {
return res.status(401).json({ message: 'Unauthorized' })
}
@@ -112,7 +118,7 @@ app.post('/cloudflare', async (req, res) => {
}
let cacheKey, cached
if (CACHE_ENABLED && data.mode === "iuam") {
if (CACHE_ENABLED && data.mode === "iuam" && !data.include_html && !data.include_cookies) {
cacheKey = JSON.stringify(data)
cached = readCache(cacheKey)
@@ -150,7 +156,7 @@ app.post('/cloudflare', async (req, res) => {
.then(r => ({ ...r }))
.catch(err => ({ code: 500, message: err.message }))
if (CACHE_ENABLED && (!result.code || result.code === 200)) {
if (CACHE_ENABLED && !data.include_html && !data.include_cookies && (!result.code || result.code === 200)) {
writeCache(cacheKey, result)
}
break