allow more types in cookies

This commit is contained in:
Thephaseless 2024-07-24 15:53:14 +00:00
parent 9fec26b557
commit 798fa5e0b9

View File

@ -21,7 +21,7 @@ class ProtectionTriggeredError(Exception):
class Solution(BaseModel):
url: str
status: int
cookies: list[dict]
cookies: list
userAgent: str # noqa: N815 # Ignore to preserve compatibility
headers: dict[str, Any]
response: str
@ -45,11 +45,7 @@ class LinkResponse(BaseModel):
):
message = "Passed challenge" if challenged else "Challenge not detected"
user_agent = await page.js_dumps("navigator")
if not isinstance(user_agent, dict):
raise ProtectionTriggeredError("User agent is not a dictionary")
user_agent = user_agent["userAgent"]
re.sub(pattern="HEADLESS", repl="", string=user_agent, flags=re.IGNORECASE)
user_agent = await cls.get_useragent(page)
# cookies = await page.browser.cookies.get_all(requests_cookie_format=True)
# # Convert cookies to json
@ -71,6 +67,15 @@ class LinkResponse(BaseModel):
startTimestamp=start_timestamp,
)
@classmethod
async def get_useragent(cls, page):
user_agent = await page.js_dumps("navigator")
if not isinstance(user_agent, dict):
raise ProtectionTriggeredError("User agent is not a dictionary")
user_agent = user_agent["userAgent"]
re.sub(pattern="HEADLESS", repl="", string=user_agent, flags=re.IGNORECASE)
return user_agent
class NoChromeExtentionError(Exception):
"""No chrome extention found."""