pg: dlc: try/catch for each dlc, #55

This commit is contained in:
Ralf Vogler 2023-05-18 17:32:02 +02:00
parent 0d074d0397
commit 7fb872608d

View file

@ -264,6 +264,7 @@ try {
await games.screenshot({ path: p }); // screenshot of all claimed games await games.screenshot({ path: p }); // screenshot of all claimed games
} }
// https://github.com/vogler/free-games-claimer/issues/55
if (cfg.pg_claimdlc) { if (cfg.pg_claimdlc) {
console.log('Trying to claim in-game content...'); console.log('Trying to claim in-game content...');
await page.click('button[data-type="InGameLoot"]'); await page.click('button[data-type="InGameLoot"]');
@ -303,27 +304,32 @@ try {
db.data[user][title] ||= { title, time: datetime(), store: 'DLC', status: 'failed: need account linking' }; db.data[user][title] ||= { title, time: datetime(), store: 'DLC', status: 'failed: need account linking' };
const notify_game = { title, url }; const notify_game = { title, url };
notify_games.push(notify_game); // status is updated below notify_games.push(notify_game); // status is updated below
await page.goto(url, { waitUntil: 'domcontentloaded' }); try {
// most games have a button 'Get in-game content' await page.goto(url, { waitUntil: 'domcontentloaded' });
// epic-games: Fall Guys: Claim now -> Continue -> Go to Epic Games (despite account linked and logged into epic-games) -> not tied to account but via some cookie? // most games have a button 'Get in-game content'
await Promise.any([page.click('button:has-text("Get in-game content")'), page.click('button:has-text("Claim your gift")'), page.click('button:has-text("Claim now")').then(() => page.click('button:has-text("Continue")'))]); // epic-games: Fall Guys: Claim now -> Continue -> Go to Epic Games (despite account linked and logged into epic-games) -> not tied to account but via some cookie?
page.click('button:has-text("Continue")').catch(_ => { }); await Promise.any([page.click('button:has-text("Get in-game content")'), page.click('button:has-text("Claim your gift")'), page.click('button:has-text("Claim now")').then(() => page.click('button:has-text("Continue")'))]);
const linkAccountModal = page.locator('[data-a-target="LinkAccountModal"]'); page.click('button:has-text("Continue")').catch(_ => { });
const linkAccountButton = linkAccountModal.locator('[data-a-target="LinkAccountButton"]'); const linkAccountModal = page.locator('[data-a-target="LinkAccountModal"]');
if (await linkAccountButton.count()) { const linkAccountButton = linkAccountModal.locator('[data-a-target="LinkAccountButton"]');
console.error(' Missing account linking:', await linkAccountButton.innerText()); if (await linkAccountButton.count()) {
} else if(await page.locator('text=Link game account').count()) { // epic-games only? console.error(' Missing account linking:', await linkAccountButton.innerText());
console.error(' Missing account linking:', await page.locator('button[data-a-target="gms-cta"]').innerText()); } else if(await page.locator('text=Link game account').count()) { // epic-games only?
} else { console.error(' Missing account linking:', await page.locator('button[data-a-target="gms-cta"]').innerText());
const code = await page.inputValue('input[type="text"]'); } else {
console.log(' Code to redeem game:', code); const code = await page.inputValue('input[type="text"]');
db.data[user][title].code = code; console.log(' Code to redeem game:', code);
db.data[user][title].status = 'claimed'; db.data[user][title].code = code;
// notify_game.status = `<a href="${redeem[store]}">${redeem_action}</a> ${code} on ${store}`; db.data[user][title].status = 'claimed';
// notify_game.status = `<a href="${redeem[store]}">${redeem_action}</a> ${code} on ${store}`;
}
// await page.pause();
} catch (error) {
console.error(error);
} finally {
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
await page.click('button[data-type="InGameLoot"]');
} }
// await page.pause();
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
await page.click('button[data-type="InGameLoot"]');
} }
} }
} catch (error) { } catch (error) {