return full cookie jar on request
Some checks failed
CI / release (push) Failing after 30s

This commit is contained in:
estebanthilliez
2026-04-24 22:26:27 +02:00
parent 772ed5a176
commit 2220b92849
4 changed files with 56 additions and 18 deletions

View File

@@ -8,7 +8,29 @@ function logBrowserCookies({ domain, cookieName, cookies }) {
)
}
async function waitForCookie({ domain, proxy, cookieName }, page) {
function buildCookieResponse({ cookieName, matchedCookie, userAgent, elapsedTime, cookies, includeCookies }) {
const result = {
cookie_name: matchedCookie?.name ?? cookieName,
cookie_value: matchedCookie?.value ?? null,
user_agent: userAgent,
elapsed_time: elapsedTime,
}
if (matchedCookie) {
result.cookie_domain = matchedCookie.domain
result.cookie_path = matchedCookie.path
result.http_only = matchedCookie.httpOnly
result.secure = matchedCookie.secure
}
if (includeCookies) {
result.cookies = cookies
}
return result
}
async function waitForCookie({ domain, proxy, cookieName, includeCookies }, page) {
if (!domain) throw new Error("Missing domain parameter")
if (!cookieName) throw new Error("Missing cookieName parameter")
@@ -33,16 +55,14 @@ async function waitForCookie({ domain, proxy, cookieName }, page) {
if (match) {
logBrowserCookies({ domain, cookieName, cookies })
return {
cookie_name: match.name,
cookie_value: match.value,
cookie_domain: match.domain,
cookie_path: match.path,
http_only: match.httpOnly,
secure: match.secure,
user_agent: userAgent,
elapsed_time: (Date.now() - startTime) / 1000,
}
return buildCookieResponse({
cookieName,
matchedCookie: match,
userAgent,
elapsedTime: (Date.now() - startTime) / 1000,
cookies,
includeCookies,
})
}
await sleep(pollInterval)
@@ -51,12 +71,13 @@ async function waitForCookie({ domain, proxy, cookieName }, page) {
const cookies = await page.cookies()
logBrowserCookies({ domain, cookieName, cookies })
return {
cookie_name: cookieName,
cookie_value: null,
user_agent: userAgent,
elapsed_time: (Date.now() - startTime) / 1000,
}
return buildCookieResponse({
cookieName,
userAgent,
elapsedTime: (Date.now() - startTime) / 1000,
cookies,
includeCookies,
})
}
module.exports = waitForCookie