From 9f113d6a3f42f167fa11cdb29756c4cd3334e902 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Wed, 10 Jul 2024 10:54:06 -0500 Subject: [PATCH] xactfetch: Switch to headed Chrome Earlier this week, `xactfetch` stopped being able to log in to the Chase website. After logging in, the website just popped up a message that said "It looks like this part of our website isn't working right now," with a hint that I should try a different browser. I suspect they have enhanced their bot detection/scraping resistance, because the error only occurs when `xactfetch` is run from inside a container. It happens every time in that case, but never when I run it on my computer directly. After several hours of messing with this, the only way I was able to get it to work is to use full-blown headed Chromium. Neither headless nor headed Firefox works, nor does headless Chromium. This is a bit cumbersome, but not really a big deal. Headed Chromium works fine in an Xvfb session. --- .containerignore | 1 + Containerfile | 12 ++++++++---- entrypoint.sh | 3 +++ xactfetch.py | 3 +-- 4 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 entrypoint.sh diff --git a/.containerignore b/.containerignore index e6e6455..1f60177 100644 --- a/.containerignore +++ b/.containerignore @@ -1,5 +1,6 @@ * !.git +!entrypoint.sh !pinentry-stub.sh !pyproject.toml !xactfetch.py diff --git a/Containerfile b/Containerfile index ae9b45c..4b29f6a 100644 --- a/Containerfile +++ b/Containerfile @@ -47,11 +47,16 @@ RUN --mount=type=cache,target=/var/cache \ libXrandr \ libXrender \ libXtst \ + libdrm \ libxcb \ + mesa-libgbm \ + nspr \ + nss \ pango \ python3 \ python3-pip \ tini \ + xorg-x11-server-Xvfb \ && echo xactfetch:x:2468: >> /etc/group \ && echo xactfetch:*:2468:2468:xactfetch:/var/lib/xactfetch:/sbin/nologin >> /etc/passwd \ && : @@ -62,7 +67,8 @@ RUN --mount=type=bind,from=build,source=/,target=/build \ python3 -m pip install --no-index -f /build/wheels xactfetch \ && cp /build/root/.cargo/bin/rbw* /usr/local/bin/ \ && install /build/src/pinentry-stub.sh /usr/local/bin/pinentry-stub \ - && playwright install firefox \ + && install /build/src/entrypoint.sh /entrypoint.sh \ + && playwright install chromium \ && : VOLUME /var/lib/xactfetch @@ -71,6 +77,4 @@ WORKDIR /var/lib/xactfetch USER 2468:2468 -ENV XDG_CONFIG_HOME=/etc - -ENTRYPOINT ["tini", "xactfetch", "--"] +ENTRYPOINT ["tini", "/entrypoint.sh", "--"] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..3e21621 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +exec xvfb-run -e /dev/stderr -s '-screen 0 1920x1080x24 -nolisten unix' xactfetch "$@" diff --git a/xactfetch.py b/xactfetch.py index 3ce1b28..e0efac5 100644 --- a/xactfetch.py +++ b/xactfetch.py @@ -721,8 +721,7 @@ async def amain() -> None: end_date = datetime.date.today() - datetime.timedelta(days=1) failed = False async with async_playwright() as pw, secrets: - headless = os.environ.get('DEBUG_HEADLESS_BROWSER', '1') == '1' - browser = await pw.firefox.launch(headless=headless) + browser = await pw.chromium.launch(headless=False) page = await browser.new_page() banks = sys.argv[1:] or list(ACCOUNTS.keys()) if 'commerce' in banks: