add headless env

This commit is contained in:
Thephaseless 2025-01-02 12:18:21 +00:00
parent a09272662b
commit e858539ff9
3 changed files with 14 additions and 7 deletions

View File

@ -26,8 +26,9 @@ An alternative to [FlareSolverr](https://github.com/FlareSolverr/FlareSolverr) a
## Options ## Options
| Env | Default | Description | | Env | Default | Description |
| ---------- | ------- | -------------------------------------------------------------------------------------------------------------------------- | | -------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| `USE_XVFB` | `false` | Use Xvfb instead of headless chromium. (Can cause performance hog [#14](https://github.com/ThePhaseless/Byparr/issues/14)) | | `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 ## Tags

11
main.py
View File

@ -14,8 +14,8 @@ import src
import src.utils import src.utils
import src.utils.consts import src.utils.consts
from src.models.requests import LinkRequest, LinkResponse, Solution from src.models.requests import LinkRequest, LinkResponse, Solution
from src.utils import consts, logger from src.utils import logger
from src.utils.consts import LOG_LEVEL from src.utils.consts import LOG_LEVEL, USE_HEADLESS, USE_XVFB
app = FastAPI(debug=LOG_LEVEL == logging.DEBUG, log_level=LOG_LEVEL) 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) # start_time = int(time.time() * 1000)
with SB( 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: ) as sb:
try: try:
sb: BaseCase sb: BaseCase

View File

@ -27,7 +27,8 @@ LOG_LEVEL = logging.getLevelNamesMapping()[LOG_LEVEL.upper()]
VERSION = get_version_from_env() or "unknown" 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 = [ CHALLENGE_TITLES = [
# Cloudflare # Cloudflare