Skip to content

Commit

Permalink
eg: fix changed button locators
Browse files Browse the repository at this point in the history
  • Loading branch information
vogler committed Aug 1, 2024
1 parent a39d737 commit d9e91d2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions epic-games.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ try {
for (const url of urls) {
if (cfg.time) console.time('claim game');
await page.goto(url); // , { waitUntil: 'domcontentloaded' });
const btnText = await page.locator('//button[@data-testid="purchase-cta-button"][not(contains(.,"Loading"))]').first().innerText(); // barrier to block until page is loaded
const purcahseBtn = page.locator('aside button').first();
const btnText = (await purcahseBtn.innerText()).toLowerCase(); // barrier to block until page is loaded

// click Continue if 'This game contains mature content recommended only for ages 18+'
if (await page.locator('button:has-text("Continue")').count() > 0) {
Expand Down Expand Up @@ -187,12 +188,12 @@ try {
const notify_game = { title, url, status: 'failed' };
notify_games.push(notify_game); // status is updated below

if (btnText.toLowerCase() == 'in library') {
if (btnText == 'in library') {
console.log(' Already in library! Nothing to claim.');
notify_game.status = 'existed';
db.data[user][game_id].status ||= 'existed'; // does not overwrite claimed or failed
if (db.data[user][game_id].status.startsWith('failed')) db.data[user][game_id].status = 'manual'; // was failed but now it's claimed
} else if (btnText.toLowerCase() == 'requires base game') {
} else if (btnText == 'requires base game') {
console.log(' Requires base game! Nothing to claim.');
notify_game.status = 'requires base game';
db.data[user][game_id].status ||= 'failed:requires-base-game';
Expand All @@ -205,7 +206,7 @@ try {
urls.push(url); // add add-on itself again
} else { // GET
console.log(' Not in library yet! Click GET.');
await page.click('[data-testid="purchase-cta-button"]', { delay: 11 }); // got stuck here without delay (or mouse move), see #75, 1ms was also enough
await purcahseBtn.click({ delay: 11 }); // got stuck here without delay (or mouse move), see #75, 1ms was also enough

// click Continue if 'Device not supported. This product is not compatible with your current device.' - avoided by Windows userAgent?
page.click('button:has-text("Continue")').catch(_ => { }); // needed since change from Chromium to Firefox?
Expand Down Expand Up @@ -252,7 +253,7 @@ try {
await iframe.locator('button:has-text("Place Order"):not(:has(.payment-loading--loading))').click({ delay: 11 });

// 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")');
const btnAgree = iframe.locator('button:has-text("I Accept")');
btnAgree.waitFor().then(() => btnAgree.click()).catch(_ => { }); // EU: wait for and click 'I Agree'
try {
// context.setDefaultTimeout(100 * 1000); // give time to solve captcha, iframe goes blank after 60s?
Expand Down

9 comments on commit d9e91d2

@Kaschtelator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that nothing worked here


Build: Mon, 06 Nov 2023 18:41:08 +0000
Xvfb display server created screen with resolution 1920x1080
VNC is running on port 5900 (no password!)
noVNC (VNC via browser) is running on http://localhost:6080

2024-08-01 18:14:45.658 started checking epic-games
Signed in as Zensiert
Free games: [
  'https://store.epicgames.com/en-US/p/lumbearjack-b5bedf',
  'https://store.epicgames.com/en-US/p/rawmen-03f74e'
]
--- Exception:
locator.innerText: Timeout 60000ms exceeded.
=========================== logs ===========================
waiting for locator('xpath=//button[@data-testid="purchase-cta-button"][not(contains(.,"Loading"))]').first()
============================================================
    at /fgc/epic-games.js:144:124 {
  name: 'TimeoutError'
}
2024-08-01 18:16:00.772 started checking prime-gaming
Signed in as Zensiert
Number of already claimed games (total): 20
Number of free unclaimed games (Prime Gaming): 4
Current free game: Deus Ex: Mankind Divided
--- Exception:
TypeError: Cannot read properties of null (reading 'click')
    at file:///fgc/prime-gaming.js:116:54
    at runNextTicks (node:internal/process/task_queues:60:5)
    at process.processImmediate (node:internal/timers:449:9)
2024-08-01 18:16:11.859 started checking gog
Signed in as Zensiert
Currently no free giveaway!




@vogler
Copy link
Owner Author

@vogler vogler commented on d9e91d2 Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build: Mon, 06 Nov 2023 18:41:08 +0000

No wonder if you're using such an old version.

@Kaschtelator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use the version that Docker pulls from you.
If you keep your github project properly up to date, the correct version would also be pulled.

@vogler
Copy link
Owner Author

@vogler vogler commented on d9e91d2 Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image gets built automatically for every commit. Use the command from the readme and you'll have the current version.

@Kaschtelator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see the error. Everyone will of course pull the "latest" and not the "main" that you recently updated.
Now I've changed it to Docker and it's working. 😁

Bild_2024-08-02_110932620

@vogler
Copy link
Owner Author

@vogler vogler commented on d9e91d2 Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was due to a CI change to build branches.
Pulling latest is a bad convention since it's just the default tag for untagged builds.
But given the numbers it's probably a good idea to also tag main as latest 😄

@PilaScat
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for me epic tells this after the captcha:
image

@vogler
Copy link
Owner Author

@vogler vogler commented on d9e91d2 Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PilaScat See the pinned issue. I have no issues running it without Docker.

@vogler
Copy link
Owner Author

@vogler vogler commented on d9e91d2 Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to push main with tag latest and deleted the image tagged with main in 23a611a.

Please sign in to comment.