dev #1

Merged
nocci merged 51 commits from dev into main 2026-03-06 16:31:29 +01:00
Showing only changes of commit 2aaa0cdd1a - Show all commits

View file

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