optional xvfb support

This commit is contained in:
Thephaseless 2024-12-18 13:29:00 +00:00
parent 0ccfa1f6a9
commit 2b28d0587a
5 changed files with 15 additions and 11 deletions

View File

@ -3,4 +3,5 @@ FROM debian:latest
RUN apt update && apt upgrade -y && apt install -y chromium chromium-driver xvfb git
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:$PATH"
ENV PATH="/root/.local/bin:$PATH" \
UV_LINK_MODE=copy

View File

@ -2,9 +2,6 @@
An alternative to [FlareSolverr](https://github.com/FlareSolverr/FlareSolverr) as a drop-in replacement, build with [seleniumbase](https://seleniumbase.io/) and [FastAPI](https://fastapi.tiangolo.com).
> [!CAUTION]
> From now on, Byparr will clear all chrome processes longer than specified in `MAX_CHROME_LIFETIME` environment variable (default is 300 seconds). To disable this behavior, set `MAX_CHROME_LIFETIME` to `0`.
> [!IMPORTANT]
> Due to recent challenge changes, this software does not guarantee that the Cloudflare challenge will be bypassed. Cloudflare likely requires valid network traffic originating from the users public IP address to mark a connection as legitimate. While this tool may bypass the initial browser check, it does not ensure that requests will consistently pass Cloudflare's validation. More testing and data are required to understand how Cloudflare identifies connections and requests as valid. Invalid requests will result in Byparr's looping and eventually time-outing.
@ -14,7 +11,7 @@ An alternative to [FlareSolverr](https://github.com/FlareSolverr/FlareSolverr) a
> [!NOTE]
> Thanks to FastAPI implementation, now you can also see the API documentation at `/docs` or `/` (redirect to `/docs`) endpoints.
## Troubleshooting
## Troubleshooting (Docker required)
1. Clone repo to the host that has the container has issues on.
2. Using vscode and `SSH extension`, connect to the host and open repo in it.
@ -26,6 +23,12 @@ An alternative to [FlareSolverr](https://github.com/FlareSolverr/FlareSolverr) a
1. If code works, congrats! (not really) You are on your own.
2. If it does not, try on another host or network and create an issue if problem persists.
## 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)) |
## Tags
- `v*.*.*`/`latest` - Releases considered stable
@ -35,7 +38,7 @@ An alternative to [FlareSolverr](https://github.com/FlareSolverr/FlareSolverr) a
### Docker Compose
See `docker-compose.yaml`
See `compose.yaml`
### Docker

View File

@ -14,7 +14,7 @@ import src
import src.utils
import src.utils.consts
from src.models.requests import LinkRequest, LinkResponse, Solution
from src.utils import consts, kill_chromium_processes, logger
from src.utils import consts, logger
from src.utils.consts import LOG_LEVEL
app = FastAPI(debug=LOG_LEVEL == logging.DEBUG, log_level=LOG_LEVEL)
@ -35,8 +35,6 @@ async def health_check():
health_check_request = read_item(
LinkRequest.model_construct(url="https://prowlarr.servarr.com/v1/ping")
)
if consts.MAX_CHROME_LIFETIME > 0:
kill_chromium_processes()
if health_check_request.solution.status != HTTPStatus.OK:
raise HTTPException(
@ -56,7 +54,9 @@ def read_item(request: LinkRequest) -> LinkResponse:
response: LinkResponse
# start_time = int(time.time() * 1000)
with SB(uc=True, locale_code="en", test=False, ad_block=True) as sb:
with SB(
uc=True, locale_code="en", test=False, ad_block=True, xvfb=consts.USE_XVFB
) as sb:
try:
sb: BaseCase
global cookies # noqa: PLW0603

View File

@ -27,7 +27,7 @@ LOG_LEVEL = logging.getLevelNamesMapping()[LOG_LEVEL.upper()]
VERSION = get_version_from_env() or "unknown"
MAX_CHROME_LIFETIME = int(os.getenv("MAX_CHROME_LIFETIME", "300"))
USE_XVFB = os.getenv("USE_XVFB") in ["true", "1"]
CHALLENGE_TITLES = [
# Cloudflare