fix: wait for prime-gaming MFA prompt
All checks were successful
build-and-push / lint (push) Successful in 5s
build-and-push / sonar (push) Successful in 12s
build-and-push / docker (push) Successful in 1m10s

This commit is contained in:
nocci 2025-12-31 10:51:13 +00:00
parent e6c43c8de6
commit 2aaa0cdd1a

View file

@ -34,6 +34,26 @@ await page.setViewportSize({ width: cfg.width, height: cfg.height }); // workaro
const notify_games = [];
let user;
const waitForSignedInOrMFA = async p => {
const otpLocator = p.locator('#auth-mfa-otpcode, input[name=otpCode]');
const waitSignedIn = p.waitForURL('**/claims/**signedIn=true', { timeout: cfg.login_timeout }).then(() => true).catch(() => false);
const waitMFA = (async () => {
try {
await otpLocator.waitFor({ timeout: cfg.login_timeout });
} catch {
return false;
}
await handleMFA(p);
try {
await p.waitForURL('**/claims/**signedIn=true', { timeout: cfg.login_timeout });
} catch {
// if it still fails, caller will handle via timeout
}
return true;
})();
await Promise.race([waitSignedIn, waitMFA]);
};
const handleMFA = async p => {
const otpField = p.locator('#auth-mfa-otpcode, input[name=otpCode]');
if (!await otpField.count()) return false;
@ -58,7 +78,7 @@ try {
await page.click('input[type="submit"]');
await page.fill('[name=password]', password);
await page.click('input[type="submit"]');
await handleMFA(page).catch(() => {});
await waitForSignedInOrMFA(page);
try {
await page.waitForURL('**/ap/signin**');
const error = await page.locator('.a-alert-content').first().innerText();
@ -111,6 +131,7 @@ try {
await page.click('input[type="submit"]');
await page.fill('[name=password]', password);
await page.click('input[type="submit"]');
await waitForSignedInOrMFA(page);
try {
await page.waitForURL('**/ap/signin**');
const error = await page.locator('.a-alert-content').first().innerText();
@ -123,11 +144,6 @@ try {
} catch {
// navigation ok
}
try {
await handleMFA(page);
} catch {
// ignore MFA watcher errors
}
} else {
console.log('Waiting for you to login in the browser.');
await notify('prime-gaming: no longer signed in and not enough options set for automatic login.');