From e858539ff907c98a965445231f25f975c4c57a97 Mon Sep 17 00:00:00 2001 From: Thephaseless Date: Thu, 2 Jan 2025 12:18:21 +0000 Subject: [PATCH] add headless env --- README.md | 7 ++++--- main.py | 11 ++++++++--- src/utils/consts.py | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e587c16..24090f6 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,10 @@ An alternative to [FlareSolverr](https://github.com/FlareSolverr/FlareSolverr) a ## Options -| Env | Default | Description | -| ---------- | ------- | -------------------------------------------------------------------------------------------------------------------------- | -| `USE_XVFB` | `false` | Use Xvfb instead of headless chromium. (Can cause performance hog [#14](https://github.com/ThePhaseless/Byparr/issues/14)) | +| Env | Default | Description | +| -------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | +| `USE_XVFB` | `false` | Use virtual desktop with Xvfb. Requires Xvfb supported platform. (Can cause performance hog [#14](https://github.com/ThePhaseless/Byparr/issues/14)) | +| `USE_HEADLESS` | `true` | Use headless chromium. | ## Tags diff --git a/main.py b/main.py index b08b268..6de9815 100644 --- a/main.py +++ b/main.py @@ -14,8 +14,8 @@ import src import src.utils import src.utils.consts from src.models.requests import LinkRequest, LinkResponse, Solution -from src.utils import consts, logger -from src.utils.consts import LOG_LEVEL +from src.utils import logger +from src.utils.consts import LOG_LEVEL, USE_HEADLESS, USE_XVFB app = FastAPI(debug=LOG_LEVEL == logging.DEBUG, log_level=LOG_LEVEL) @@ -60,7 +60,12 @@ def read_item(request: LinkRequest) -> LinkResponse: # start_time = int(time.time() * 1000) with SB( - uc=True, locale_code="en", test=False, ad_block=True, xvfb=consts.USE_XVFB, headless=True + uc=True, + locale_code="en", + test=False, + ad_block=True, + xvfb=USE_XVFB, + headless=USE_HEADLESS, ) as sb: try: sb: BaseCase diff --git a/src/utils/consts.py b/src/utils/consts.py index ebe52b1..2eeaf77 100644 --- a/src/utils/consts.py +++ b/src/utils/consts.py @@ -27,7 +27,8 @@ LOG_LEVEL = logging.getLevelNamesMapping()[LOG_LEVEL.upper()] VERSION = get_version_from_env() or "unknown" -USE_XVFB = os.getenv("USE_XVFB") in ["true", "1"] +USE_XVFB = os.getenv("USE_XVFB", "false") in ["true", "1"] +USE_HEADLESS = os.getenv("USE_HEADLESS", "true").lower() in ["true", "1"] CHALLENGE_TITLES = [ # Cloudflare