Skip to content

Commit

Permalink
log urlSlug, #25
Browse files Browse the repository at this point in the history
  • Loading branch information
vogler committed Sep 29, 2022
1 parent e5ae4b6 commit 69d771b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion epic-games.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ try {
// click on each banner with 'Free Now'. TODO just extract the URLs and go to them in the loop
// This json contains all promotions: https://store-site-backend-static-ipv4.ak.epicgames.com/freeGamesPromotions
// Could filter data.Catalog.searchStore.elements for .promotions.promotionalOffers being set and build URL with .catalogNs.mappings[0].pageSlug or .urlSlug if not set to some wrong id like it was the case for spirit-of-the-north-f58a66
const game_sel = 'span:text-is("Free Now")';
const game_sel = 'a:has(span:text-is("Free Now"))';
await page.waitForSelector(game_sel);
// const games = await page.$$(game_sel); // 'Element is not attached to the DOM' after navigation; had `for (const game of games) { await game.click(); ... }
const n = run.n = await page.locator(game_sel).count();
console.log('Number of free games:', n);
// fixes for https://github.com/vogler/free-games-claimer/issues/25 when URL of game is changed by JS:
// await page.waitForResponse(/freeGamesPromotions/); // not enough
for (let i = 0; i < n; i++) {
console.log('urlSlug', await page.locator(game_sel).nth(i).getAttribute('href'));
await page.waitForTimeout(3000);
await page.locator(game_sel).nth(i).click(); // navigates to page for game
const btnText = await page.locator('//button[@data-testid="purchase-cta-button"][not(contains(.,"Loading"))]').first().innerText(); // barrier to block until page is loaded
Expand Down

0 comments on commit 69d771b

Please sign in to comment.