From 7971be297c0547a2e1cf5de66c3dea963380916f Mon Sep 17 00:00:00 2001 From: Trung Le Date: Sat, 9 Apr 2022 14:50:42 +0700 Subject: [PATCH] feat: use novnc, fix Thank you for buying timeout --- Dockerfile | 3 +++ docker/vnc-start.sh | 5 ++++- epic-games.js | 7 ++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4baeb48..b8c1b90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,9 @@ ENV DISPLAY :60 ENV VNC_ENABLED true ENV VNC_PASSWORD secret ENV VNC_PORT 5900 +ENV NOVNC_PORT 6080 EXPOSE 5900 +EXPOSE 6080 # Playwright ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true @@ -44,6 +46,7 @@ RUN apt-get update \ x11vnc \ curl \ tini \ + novnc websockify \ && apt-get clean \ && rm -rf \ /tmp/* \ diff --git a/docker/vnc-start.sh b/docker/vnc-start.sh index ef28937..92423ea 100755 --- a/docker/vnc-start.sh +++ b/docker/vnc-start.sh @@ -2,7 +2,10 @@ # Start VNC in a background process: x11vnc -display "$DISPLAY" -forever -shared -rfbport "${VNC_PORT:-5900}" \ - -passwd "${VNC_PASSWORD:-secret}" & + -passwd "${VNC_PASSWORD:-secret}" -bg +NOVNC_HOME=/usr/share/novnc +ln -s $NOVNC_HOME/vnc_auto.html $NOVNC_HOME/index.html +websockify -D --web "$NOVNC_HOME" "$NOVNC_PORT" "localhost:$VNC_PORT" & # Execute the given command: exec "$@" diff --git a/epic-games.js b/epic-games.js index 671ff58..1c9e975 100644 --- a/epic-games.js +++ b/epic-games.js @@ -6,7 +6,7 @@ const debug = process.env.PWDEBUG == '1'; // runs non-headless and opens https:/ const URL_CLAIM = 'https://store.epicgames.com/en-US/free-games'; const URL_LOGIN = 'https://www.epicgames.com/id/login?lang=en-US&noHostRedirect=true&redirectUrl=' + URL_CLAIM; const TIMEOUT = 20 * 1000; // 20s, default is 30s -const SCREEN_WIDTH = Number(process.env.SCREEN_WIDTH) || 1280; +const SCREEN_WIDTH = Number(process.env.SCREEN_WIDTH) - 80 || 1280; const SCREEN_HEIGHT = Number(process.env.SCREEN_HEIGHT) || 1280; // https://playwright.dev/docs/auth#multi-factor-authentication @@ -86,10 +86,7 @@ for (let i = 1; i <= n; i++) { // I Agree button is only shown for EU accounts! https://github.com/vogler/free-games-claimer/pull/7#issuecomment-1038964872 const btnAgree = iframe.locator('button:has-text("I Agree")'); try { - await Promise.any([btnAgree.waitFor(), page.waitForSelector('text=Thank you for buying')]); // EU: wait for agree button, non-EU: potentially done - // await clickIfExists('button:has-text("I Agree")', iframe); // default arg: FrameLocator is incompatible with Page and even Locator... - if (await btnAgree.count() > 0) - await btnAgree.click(); + await Promise.any([btnAgree.waitFor().then(() => btnAgree.click()), page.waitForSelector('text=Thank you for buying')]); // EU: wait for agree button, non-EU: potentially done // TODO check for hcaptcha - the following is even true when no captcha is shown... // if (await iframe.frameLocator('#talon_frame_checkout_free_prod').locator('text=Please complete a security check to continue').count() > 0) { // console.error('Encountered hcaptcha. Giving up :(');