claabs / epicgames-freegames-node

Automatically login and find available free games the Epic Games Store. Sends you a prepopulated checkout link so you can complete the checkout after logging in. Supports multiple accounts, login sessions, and scheduled runs.
https://hub.docker.com/r/charlocharlie/epicgames-freegames
MIT License
1.34k stars 91 forks source link

fix: TimeoutError while waiting for receipt #315

Closed SavvasMohito closed 1 year ago

SavvasMohito commented 1 year ago

Problem investigation

After facing the issue mentioned in #298, I discovered that the cause of the problem came from purchase.ts, specifically the race condition in lines 57-64. In my case, the order button case always won the race condition, but the button was not clicked after all. See logs below.

...
[2023-01-20 11:10:06.855 +0000] DEBUG: Waiting for order button or cookie dialog
[2023-01-20 11:10:06.900 +0000] DEBUG: Clicking placeOrderButton
[2023-01-20 11:10:07.066 +0000] DEBUG: Waiting for receipt, captcha, refund dialog, or error
[2023-01-20 11:12:07.440 +0000] WARN: waiting for function failed: timeout 120000ms exceeded
...

After this, the screenshot that was getting captured showed that the script hangs at the purchase page, with a cookie dialog and the purchase button below it.

error-2023-01-20T10-50-41 441Z

Initially I tried adding some delay in the original code, just before clicking the place order button, but it did not work.

The fix

I was able to resolve this issue by modifying the code of purchase.ts and separating the two waitForSelectors of the race condition. I first run the check for the cookie dialog and then the one for the place order button. I needed to add a two-second delay between them, otherwise, the script would freeze and timeout again. My suggested code worked with three different accounts.

I hope this fix is enough to solve most people's timeout errors or at least help you make a fix of your own.

claabs commented 1 year ago

Thanks for looking into this. I'd like to try to avoid those 3 second "wait for something to happen" timeouts, and be more reactive. When I get some time later today, I'll look deeper into it.

claabs commented 1 year ago

@SavvasMohito I couldn't think of an elegant approach that avoids the 3 second "wait for something to happen" timeout, but I did take a shot at removing the 2 second wait after clicking the cookie button.

I'm having trouble testing through my VPN, so I can't get the cookie dialog to appear. If you could re-test, that would be appreciated.

TIL the puppeteer page.click() function requires the element to be visible. So ultimately, the low resolution of the automation caused the place order button to be covered.

SavvasMohito commented 1 year ago

@claabs Thank you for coming back to this, your commit looks much cleaner. I have no experience with puppeteer, but it looks quite fun! I'll make a build with your changes tomorrow and provide an update. :)

SavvasMohito commented 1 year ago

Hello again @claabs. Sorry for the delayed response, I was travelling for the past 5 days so I had no time to try your new commit. I just pulled your changes, built a fresh docker image and tried it out with a temporary account. Good news, it works! No issues whatsoever, at least for my setup. Below I'm providing a part of the debug logs just for reference. Everything looks normal to me. Thank you for your effort!

...
[2023-01-26 11:03:51.664 +0000] DEBUG: Launching a new page
    user: "dinev45083@crtsec.com"
[2023-01-26 11:03:52.478 +0000] INFO: Loading purchase page
    user: "dinev45083@crtsec.com"
    purchaseUrl: "https://www.epicgames.com/store/purchase?highlightColor=0078f2&offers=1-6a6d54e5b4ef4fb0b3dad1d02a320376-63352c1c0eed4ab9a640dafee08eff54&orderId&purchaseToken&showNavigation=true"
[2023-01-26 11:04:06.648 +0000] DEBUG: Waiting for cookie dialog
    user: "dinev45083@crtsec.com"
[2023-01-26 11:04:06.676 +0000] DEBUG: Clicking cookieDialog
    user: "dinev45083@crtsec.com"
[2023-01-26 11:04:06.920 +0000] DEBUG: Waiting for cookieDialog to be hidden
    user: "dinev45083@crtsec.com"
[2023-01-26 11:04:07.331 +0000] DEBUG: Waiting for order button
    user: "dinev45083@crtsec.com"
[2023-01-26 11:04:07.353 +0000] DEBUG: Clicking placeOrderButton
    user: "dinev45083@crtsec.com"
[2023-01-26 11:04:07.516 +0000] DEBUG: Waiting for receipt, captcha, refund dialog, or error
    user: "dinev45083@crtsec.com"
[2023-01-26 11:04:07.587 +0000] DEBUG: Clicking euRefundAgreeButton
    user: "dinev45083@crtsec.com"
[2023-01-26 11:04:09.397 +0000] DEBUG: Waiting for receipt, captcha, refund dialog, or error
    user: "dinev45083@crtsec.com"
[2023-01-26 11:04:11.433 +0000] DEBUG: Captcha detected
    user: "dinev45083@crtsec.com"
[2023-01-26 11:04:11.436 +0000] INFO: Go to this URL and do something
    user: "dinev45083@crtsec.com"
    url: "http://10.68.51.207:3030/?targetId=B08995A8B7CF9C77F1A1AEEB03049435"
[2023-01-26 11:04:32.598 +0000] INFO: Done purchasing Epistory - Typing Chronicles
    user: "dinev45083@crtsec.com"
[2023-01-26 11:04:32.598 +0000] DEBUG: Closing browser
    user: "dinev45083@crtsec.com"
...
Fastjur commented 1 year ago

Hello again @claabs. Sorry for the delayed response, I was travelling for the past 5 days so I had no time to try your new commit. I just pulled your changes, built a fresh docker image and tried it out with a temporary account. Good news, it works! No issues whatsoever, at least for my setup. Below I'm providing a part of the debug logs just for reference. Everything looks normal to me. Thank you for your effort!

Hey, just wanted to let you know you may have accidentally leaked your email with this comment (in the logs). Not sure if that is intentional, just letting you know :)

Thanks both for your effort with this issue, I was having it too!

SavvasMohito commented 1 year ago

Hey, just wanted to let you know you may have accidentally leaked your email with this comment (in the logs). Not sure if that is intentional, just letting you know :)

Hello, as mentioned in my message, that was a temporary generated email (that no longer exists now, lol) so no worries.

Thanks both for your effort with this issue, I was having it too!

You are welcome! Happy I could be of help.