|
|
@@ -285,45 +285,15 @@ export async function refresh(mode: string): Promise<CredentialsPayload> {
|
|
|
await page.waitForLoadState('domcontentloaded');
|
|
|
|
|
|
if (!page.url().includes('ses=')) {
|
|
|
- if (email && password && page.url().includes('account.booking.com/sign-in')) {
|
|
|
- console.error('Session expired — attempting auto-login (headless)...');
|
|
|
- let autoLoginOk = false;
|
|
|
- try {
|
|
|
- await performLogin(page, email, password);
|
|
|
- await page.waitForURL(
|
|
|
- url => url.toString().includes('ses=') || needsChallenge(url.toString()),
|
|
|
- { timeout: 60_000 },
|
|
|
- );
|
|
|
- if (needsChallenge(page.url())) {
|
|
|
- await handlePostLoginChallenge(page, smsMasked);
|
|
|
- await page.waitForURL('**ses=**', { timeout: 120_000 });
|
|
|
- }
|
|
|
- autoLoginOk = true;
|
|
|
- } catch (err) {
|
|
|
- console.error(`[booking] Headless auto-login failed (${(err as Error).message}) — falling back to headed browser.`);
|
|
|
- }
|
|
|
- if (!autoLoginOk) {
|
|
|
- if (FORCE_HEADLESS) {
|
|
|
- await context.close();
|
|
|
- throw new Error('Session expired and headless auto-login failed — re-run without HEADLESS=1.');
|
|
|
- }
|
|
|
- // Reset so the headed browser can attempt login cleanly.
|
|
|
- loginDisabledReason = null;
|
|
|
- await context.close();
|
|
|
- headless = false;
|
|
|
- context = await openCtx(false);
|
|
|
- page = context.pages()[0] ?? await context.newPage();
|
|
|
- }
|
|
|
- } else if (FORCE_HEADLESS) {
|
|
|
+ if (FORCE_HEADLESS) {
|
|
|
await context.close();
|
|
|
throw new Error('Session expired — re-run without HEADLESS=1 to re-authenticate.');
|
|
|
- } else {
|
|
|
- console.error('Profile session expired — switching to headed browser for login...');
|
|
|
- await context.close();
|
|
|
- headless = false;
|
|
|
- context = await openCtx(false);
|
|
|
- page = context.pages()[0] ?? await context.newPage();
|
|
|
}
|
|
|
+ console.error('Session expired — switching to headed browser for login...');
|
|
|
+ await context.close();
|
|
|
+ headless = false;
|
|
|
+ context = await openCtx(false);
|
|
|
+ page = context.pages()[0] ?? await context.newPage();
|
|
|
} else {
|
|
|
console.error('Session valid — continuing silently.');
|
|
|
}
|