fix: Robust login detection with multiple confirmation checks
- isLoggedIn(): Wait for egs-navigation element, add timeout - attemptBrowserLogin(): Multiple login status checks after navigation - Manual login wait loop: Confirm stable login state before proceeding - Add delays to let page stabilize before checking login status - Better logging for debugging login flow Fixes issue where login succeeded but was reported as failed due to timing
This commit is contained in:
parent
5d41b323e5
commit
1c16b16889
1 changed files with 43 additions and 7 deletions
|
|
@ -104,9 +104,14 @@ const claimGame = async (page, game) => {
|
|||
// Check if logged in
|
||||
const isLoggedIn = async page => {
|
||||
try {
|
||||
// Wait for egs-navigation element to be present
|
||||
await page.locator('egs-navigation').waitFor({ state: 'attached', timeout: 5000 });
|
||||
const attr = await page.locator('egs-navigation').getAttribute('isloggedin');
|
||||
return attr === 'true';
|
||||
} catch {
|
||||
const isLogged = attr === 'true';
|
||||
L.trace({ isLogged, attr }, 'Login status check');
|
||||
return isLogged;
|
||||
} catch (err) {
|
||||
L.trace({ err: err.message }, 'Login status check failed');
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
|
@ -206,11 +211,29 @@ const attemptBrowserLogin = async (page, context) => {
|
|||
|
||||
// Wait for successful login
|
||||
try {
|
||||
L.trace('Waiting for navigation to free-games page');
|
||||
await page.waitForURL('**/free-games**', { timeout: cfg.login_timeout });
|
||||
L.info('Login successful');
|
||||
return await isLoggedIn(page);
|
||||
|
||||
// Give page time to fully load and egs-navigation to update
|
||||
L.trace('Waiting for page to stabilize');
|
||||
await page.waitForTimeout(3000);
|
||||
|
||||
// Check multiple times to ensure stable login state
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const logged = await isLoggedIn(page);
|
||||
if (logged) {
|
||||
L.info('Login confirmed');
|
||||
return true;
|
||||
}
|
||||
L.trace({ attempt: i + 1 }, 'Login not yet confirmed, retrying');
|
||||
await page.waitForTimeout(2000);
|
||||
}
|
||||
|
||||
L.warn('Login URL reached but login status not confirmed');
|
||||
return false;
|
||||
} catch (err) {
|
||||
L.warn({ err: err.message }, 'Login URL timeout, checking if logged in anyway');
|
||||
await page.waitForTimeout(3000);
|
||||
return await isLoggedIn(page);
|
||||
}
|
||||
} catch (err) {
|
||||
|
|
@ -261,13 +284,26 @@ const ensureLoggedIn = async (page, context) => {
|
|||
const maxWait = cfg.login_timeout;
|
||||
const checkInterval = 5000;
|
||||
let waited = 0;
|
||||
let loginConfirmed = false;
|
||||
|
||||
while (waited < maxWait) {
|
||||
await page.waitForTimeout(checkInterval);
|
||||
waited += checkInterval;
|
||||
|
||||
if (await isLoggedIn(page)) {
|
||||
L.info('Manual login detected');
|
||||
// Check multiple times for stable state
|
||||
for (let i = 0; i < 2; i++) {
|
||||
if (await isLoggedIn(page)) {
|
||||
// Confirm it's stable
|
||||
await page.waitForTimeout(2000);
|
||||
if (await isLoggedIn(page)) {
|
||||
loginConfirmed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (loginConfirmed) {
|
||||
L.info('Manual login detected and confirmed');
|
||||
console.log('✅ Manual login detected!');
|
||||
break;
|
||||
}
|
||||
|
|
@ -279,7 +315,7 @@ const ensureLoggedIn = async (page, context) => {
|
|||
}
|
||||
}
|
||||
|
||||
if (!await isLoggedIn(page)) {
|
||||
if (!loginConfirmed && !await isLoggedIn(page)) {
|
||||
throw new Error('Manual login did not complete within timeout');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue