vogler / free-games-claimer

Automatically claims free games on the Epic Games Store, Amazon Prime Gaming and GOG.
GNU Affero General Public License v3.0
2.36k stars 143 forks source link

Running 'node epic-games' with cron exits with hcaptcha challenge. Manually running works everytime. #138

Closed GothicIII closed 1 year ago

GothicIII commented 1 year ago

I decided to open a new issue since other issues are unrelated.

My environment consists of debian bookworm (upgraded from bullseye yesterday) with qemu-kvm. I got a VM which does other tasks so It has enough ressource (8GB RAM) and the internet access is not filtered.

I configured it to run the cronjobs for free-games-claimer. Sadly I can't link to the tutorial I used to configure everything; it seems to be taken down. Since only epic has free offers every week I can only refer to the epic part. I don't know if the other plugins are affected or not.

If I run node epic-games from terminal over a ssh-session with X11 forwaring the script runs successfully and claims the games. I configured crontab for the user like this:

00 20 * * * node /home/user/free-games-claimer/prime-gaming.js >>/tmp/freegames_prime.log 2>&1

At 08:00PM it is executed and I get following output:

Signed in as <user>
Free games: [
  'https://store.epicgames.com/en-US/p/the-sims-4--the-daring-lifestyle-bundle'
]
Current free game: The Sims™ 4 The Daring Lifestyle Bundle
  Not in library yet! Click GET.
  Got hcaptcha challenge! Lost trust due to too many login attempts? You can solve the captcha in the browser or get a new IP address.
page.waitForSelector: Timeout 60000ms exceeded.
=========================== logs ===========================
waiting for locator('text=Thanks for your order!') to be visible
============================================================
    at file:///home/<user>/free-games-claimer/epic-games.js:212:20 {
  name: 'TimeoutError'
}
  Failed to claim! To avoid captchas try to get a new IP address.

It was speculated that the environment variables from the user are missing if ran from cron. I tried to fix the issue by editing the crontab like this:

00 20 * * * . $HOME/.profile; node /home/<user>/free-games-claimer/epic-games.js >> /tmp/freegames_epic.log 2>&1

The issue persists. If the games are claimed already, the script exits normally. I am pretty sure I can rule out X11 since it works from a local session were no X is configured (bare-metal env). I don't want to install docker just for this task. It would literally install hundreds of libraries I don't need otherwise. And nested VMs would just eat more ressources.

It would be helpful to use SHOW=1 for debugging to see what is really going on but since it runs over cron I don't know how to hijack graphical sessions for this purpose... And like already mentioned manual running the script always succeeds...

Can somebody help?

vogler commented 1 year ago

Thanks for the detailed description.

(Your first crontab line shows prime-gaming.js - I assume that's a typo.)

As long as the environment variables are set properly, dotenv should pick them up. You could include env to check.

Yea, X shouldn't be needed, but whether you get a captcha challenge depends on a number of factors, so SHOW=1 may still help.

To make sure that you actually do get a captcha challenge, run with RECORD=1 which will record a video to data/record/*.webm and a .har archive you can load in Chrome devtools to check all network requests/responses.

vogler commented 1 year ago

Any update?

GothicIII commented 1 year ago

Yesterday when I wanted to check the script asked me to login again. I claimed the game manually due to expiring and now I have to wait another week because I own already the current game.

I'll try next weekend again.

vogler commented 1 year ago

Strange, for me it stays logged in at least a week.

GothicIII commented 1 year ago

So I tried it again. Ran it with:

RECORD=1; node /home/<user>/free-games-claimer/epic-games.js >> /tmp/freegames_epic.log 2>&1

Nothing was recorded where freegames is installed. There is no record directory inside data. The error is still the same like in the opening post. I don't know how to debug this within cron when running 'node epic-games.js' from terminal works without issues. SHOW=1 won't have any effect when ran from cron since it does not spawn any x session I could look into.

Btw. The prime-plugin works without issues.

EDIT: Made a mistake. Shouldn't have used a semicolon. Hugh another week, another try. See you in a week.

vogler commented 1 year ago

🙈 Debugging the last step of the order is annoying. For stuff before, you could at least run with DRYRUN=1. If you don't want to wait until Thursday, you could make a new epic-games account (for your family/pet) and try it there.

vogler commented 1 year ago

@GothicIII Any update on this?

vogler commented 1 year ago

I'll close this for now. Did you figure out what's the issue? As you wrote, env is minimal with cronjobs: https://askubuntu.com/questions/23009/why-crontab-scripts-are-not-working But that's not a problem here since it runs the script. Setting env vars without semicolon, yes. Alternatively, you could also try running with pm2: https://pm2.keymetrics.io/docs/usage/quick-start/