Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2220b92849 |
15
README.md
15
README.md
@@ -119,13 +119,15 @@ Open a page and wait for a specific cookie to appear.
|
||||
```json
|
||||
{
|
||||
"domain": "https://example.com/",
|
||||
"cookieName": "session_id"
|
||||
"cookieName": "session_id",
|
||||
"includeCookies": true
|
||||
}
|
||||
```
|
||||
|
||||
#### Parameters
|
||||
- **`domain`** (required): Target website URL
|
||||
- **`cookieName`** (required): Cookie name to wait for
|
||||
- **`includeCookies`** (optional): Include the full browser cookie jar in the response
|
||||
- **`user_agent`** (optional): User-Agent to use for the browser session
|
||||
- **`proxy`** (optional): Proxy configuration object
|
||||
|
||||
@@ -138,6 +140,16 @@ Open a page and wait for a specific cookie to appear.
|
||||
"cookie_path": "/",
|
||||
"http_only": true,
|
||||
"secure": true,
|
||||
"cookies": [
|
||||
{
|
||||
"name": "session_id",
|
||||
"value": "abc123",
|
||||
"domain": ".example.com",
|
||||
"path": "/",
|
||||
"httpOnly": true,
|
||||
"secure": true
|
||||
}
|
||||
],
|
||||
"user_agent": "Mozilla/5.0...",
|
||||
"elapsed_time": 1.42
|
||||
}
|
||||
@@ -148,6 +160,7 @@ Open a page and wait for a specific cookie to appear.
|
||||
{
|
||||
"cookie_name": "session_id",
|
||||
"cookie_value": null,
|
||||
"cookies": [],
|
||||
"user_agent": "Mozilla/5.0...",
|
||||
"elapsed_time": 60.0
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ async def main():
|
||||
json={
|
||||
"domain": "https://example.com/",
|
||||
"cookieName": "session_id",
|
||||
"includeCookies": True,
|
||||
},
|
||||
)
|
||||
print(resp3.json())
|
||||
|
||||
@@ -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
|
||||
|
||||
3
index.js
3
index.js
@@ -173,6 +173,9 @@ app.post('/cookie', async (req, res) => {
|
||||
if (!data || typeof data.domain !== 'string' || typeof data.cookieName !== 'string') {
|
||||
return res.status(400).json({ message: 'Bad Request: missing or invalid domain/cookieName' })
|
||||
}
|
||||
if (typeof data.includeCookies !== 'undefined' && typeof data.includeCookies !== 'boolean') {
|
||||
return res.status(400).json({ message: 'Bad Request: invalid includeCookies' })
|
||||
}
|
||||
if (data.user_agent && typeof data.user_agent !== 'string') {
|
||||
return res.status(400).json({ message: 'Bad Request: invalid user_agent' })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user