From 59a5f529d8eef028a684d9679ac2b556c60c4334 Mon Sep 17 00:00:00 2001 From: Ralf Vogler Date: Thu, 17 Feb 2022 17:06:05 +0100 Subject: [PATCH] 'I Agree' button only for EU accounts, closes #7 --- epic-games.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/epic-games.js b/epic-games.js index a1d4401..7d5f4ee 100644 --- a/epic-games.js +++ b/epic-games.js @@ -112,7 +112,13 @@ const TIMEOUT = 20 * 1000; // 20s, default is 30s const iframe = page.frameLocator('#webPurchaseContainer iframe') await iframe.locator('button:has-text("Place Order")').click(); // await page.pause(); - await iframe.locator('button:has-text("I Agree")').click(); + // 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")'); + // @ts-ignore https://caniuse.com/?search=promise.any + await Promise.any([btnAgree.waitFor(), page.waitForSelector('text=Thank you for buying')]); // TODO non-EU case will fail with timeout here instead of below; could pull up try, but then it would cover future hcaptcha solving for headless as well + // 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(); // This is true even when there is no captcha challenge shown! That was the reason why old.stealth.js worked - it did not have this check... TODO check for hcaptcha // 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 :(');