fix addon passing all websites

This commit is contained in:
Thephaseless 2024-10-21 13:12:09 +00:00
parent 0713ce7ca5
commit 9ca2059b91
3 changed files with 20 additions and 11 deletions

View File

@ -31,6 +31,7 @@ async def read_item(request: LinkRequest):
logger.info(f"Request: {request}")
start_time = int(time.time() * 1000)
browser = await new_browser()
await browser.grant_all_permissions()
await asyncio.sleep(1)
page = await browser.get(request.url)
await page.bring_to_front()
@ -39,8 +40,12 @@ async def read_item(request: LinkRequest):
timeout = None
try:
challenged = await asyncio.wait_for(bypass_cloudflare(page), timeout=timeout)
except asyncio.TimeoutError:
except asyncio.TimeoutError as e:
logger.info("Timed out bypassing Cloudflare")
raise HTTPException(
detail="Timed out bypassing Cloudflare", status_code=408
) from e
browser.stop()
except Exception as e:
browser.stop()
raise HTTPException(detail="Couldn't bypass", status_code=408) from e

View File

@ -4,7 +4,7 @@ import nodriver as webdriver
from nodriver.core.element import Element
from src.utils import logger
from src.utils.consts import CHALLENGE_TITLES
from src.utils.consts import CHALLENGE_TITLES, UBLOCK_TITLE
from src.utils.extentions import download_extentions
downloaded_extentions = download_extentions()
@ -58,11 +58,13 @@ async def bypass_cloudflare(page: webdriver.Tab):
"""
challenged = False
await page
while True:
await asyncio.sleep(1)
logger.debug(f"Current page: {page.target.title}")
if page.target.title not in CHALLENGE_TITLES:
if page.target.title == UBLOCK_TITLE:
continue
return challenged
if not challenged:
@ -78,12 +80,12 @@ async def bypass_cloudflare(page: webdriver.Tab):
loaded = False
try:
elem = await page.find("lds-ring")
except asyncio.TimeoutError as e:
elem = await page.find("lds-ring", timeout=3)
except asyncio.TimeoutError:
logger.error(
"Couldn't find lds-ring, probably not a cloudflare challenge, trying again..."
)
raise InvalidElementError from e
continue
if elem is None:
logger.error("elem is None")
logger.debug(elem)
@ -115,11 +117,11 @@ async def bypass_cloudflare(page: webdriver.Tab):
logger.debug("Clicking element")
await inner_elem.mouse_click()
await asyncio.sleep(3)
else:
logger.warning(
"Couldn't find element containing shadow root, trying again..."
)
logger.debug(inner_elem)
continue
logger.warning(
"Couldn't find element containing shadow root, trying again..."
)
logger.debug(inner_elem)
else:
logger.warning("Coulnd't find checkbox, trying again...")
logger.debug(elem)

View File

@ -5,6 +5,8 @@ from pathlib import Path
LOG_LEVEL = os.getenv("LOG_LEVEL") or "INFO"
LOG_LEVEL = logging.getLevelNamesMapping()[LOG_LEVEL.upper()]
UBLOCK_TITLE = "uBO Lite — Dashboard"
CHALLENGE_TITLES = [
# Cloudflare
"Just a moment...",