page.waitForNavigation -> page.waitForURL

This commit is contained in:
Ralf Vogler 2023-02-04 21:37:04 +01:00
parent eb17a49628
commit b9e9abe546
3 changed files with 6 additions and 8 deletions

View file

@ -83,7 +83,7 @@ try {
notify('epic-games: got captcha during login. Please check.'); notify('epic-games: got captcha during login. Please check.');
}).catch(_ => { }); }).catch(_ => { });
// handle MFA, but don't await it // handle MFA, but don't await it
page.waitForNavigation({ url: '**/id/login/mfa**'}).then(async () => { page.waitForURL('**/id/login/mfa**').then(async () => {
console.log('Enter the security code to continue - This appears to be a new device, browser or location. A security code has been sent to your email address at ...'); console.log('Enter the security code to continue - This appears to be a new device, browser or location. A security code has been sent to your email address at ...');
// TODO locator for text (email or app?) // TODO locator for text (email or app?)
const otp = cfg.eg_otpkey && authenticator.generate(cfg.eg_otpkey) || await prompt({type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!'}); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them const otp = cfg.eg_otpkey && authenticator.generate(cfg.eg_otpkey) || await prompt({type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!'}); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
@ -94,7 +94,7 @@ try {
console.log('Waiting for you to login in the browser.'); console.log('Waiting for you to login in the browser.');
notify('epic-games: no longer signed in and not enough options set for automatic login.'); notify('epic-games: no longer signed in and not enough options set for automatic login.');
} }
await page.waitForNavigation({ url: URL_CLAIM }); await page.waitForURL(URL_CLAIM);
context.setDefaultTimeout(cfg.timeout); context.setDefaultTimeout(cfg.timeout);
} }
const user = await page.locator('#user span').first().innerHTML(); const user = await page.locator('#user span').first().innerHTML();

1
gog.js
View file

@ -76,7 +76,6 @@ try {
process.exit(1); process.exit(1);
} }
} }
// await page.waitForNavigation(); // TODO was blocking
context.setDefaultTimeout(cfg.timeout); context.setDefaultTimeout(cfg.timeout);
} }
const user = await page.locator('#menuUsername').first().textContent(); // innerText is uppercase due to styling! const user = await page.locator('#menuUsername').first().textContent(); // innerText is uppercase due to styling!

View file

@ -56,7 +56,7 @@ try {
await page.fill('[name=password]', password); await page.fill('[name=password]', password);
await page.check('[name=rememberMe]'); await page.check('[name=rememberMe]');
await page.click('input[type="submit"]'); await page.click('input[type="submit"]');
page.waitForNavigation({ url: '**/ap/signin**'}).then(async () => { // check for wrong credentials page.waitForURL('**/ap/signin**').then(async () => { // check for wrong credentials
const error = await page.locator('.a-alert-content').first().innerText(); const error = await page.locator('.a-alert-content').first().innerText();
console.error(error); console.error(error);
notify(`prime-gaming: login: ${error}`); notify(`prime-gaming: login: ${error}`);
@ -64,7 +64,7 @@ try {
process.exit(1); process.exit(1);
}); });
// handle MFA, but don't await it // handle MFA, but don't await it
page.waitForNavigation({ url: '**/ap/mfa**'}).then(async () => { page.waitForURL('**/ap/mfa**').then(async () => {
console.log('Two-Step Verification - enter the One Time Password (OTP), e.g. generated by your Authenticator App'); console.log('Two-Step Verification - enter the One Time Password (OTP), e.g. generated by your Authenticator App');
await page.check('[name=rememberDevice]'); await page.check('[name=rememberDevice]');
const otp = cfg.pg_otpkey && authenticator.generate(cfg.pg_otpkey) || await prompt({type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!'}); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them const otp = cfg.pg_otpkey && authenticator.generate(cfg.pg_otpkey) || await prompt({type: 'text', message: 'Enter two-factor sign in code', validate: n => n.toString().length == 6 || 'The code must be 6 digits!'}); // can't use type: 'number' since it strips away leading zeros and codes sometimes have them
@ -80,7 +80,7 @@ try {
process.exit(1); process.exit(1);
} }
} }
await page.waitForNavigation({ url: 'https://gaming.amazon.com/home?signedIn=true' }); await page.waitForURL('https://gaming.amazon.com/home?signedIn=true');
if (!cfg.debug) context.setDefaultTimeout(cfg.timeout); if (!cfg.debug) context.setDefaultTimeout(cfg.timeout);
} }
const user = await page.locator('[data-a-target="user-dropdown-first-name-text"]').first().innerText(); const user = await page.locator('[data-a-target="user-dropdown-first-name-text"]').first().innerText();
@ -125,8 +125,7 @@ try {
const title = await (await card.$('.item-card-details__body__primary')).innerText(); const title = await (await card.$('.item-card-details__body__primary')).innerText();
console.log('Current free game:', title); console.log('Current free game:', title);
if (cfg.dryrun) continue; if (cfg.dryrun) continue;
await (await card.$('text=Claim')).click(); await (await card.$('text=Claim')).click(); // goes to URL of game, no need to wait
// await page.waitForNavigation();
await Promise.any([page.click('button:has-text("Claim now")'), page.click('button:has-text("Complete Claim")'), page.waitForSelector('div:has-text("Link game account")')]); // waits for navigation await Promise.any([page.click('button:has-text("Claim now")'), page.click('button:has-text("Complete Claim")'), page.waitForSelector('div:has-text("Link game account")')]); // waits for navigation
const store_text = await (await page.$('[data-a-target="hero-header-subtitle"]')).innerText(); const store_text = await (await page.$('[data-a-target="hero-header-subtitle"]')).innerText();
// Full game for PC [and MAC] on: gog.com, Origin, Legacy Games, EPIC GAMES, Battle.net // Full game for PC [and MAC] on: gog.com, Origin, Legacy Games, EPIC GAMES, Battle.net