|
@@ -192,14 +192,32 @@ export async function refresh(mode: string): Promise<CredentialsPayload> {
|
|
|
if (!page.url().includes('ses=')) {
|
|
if (!page.url().includes('ses=')) {
|
|
|
if (email && password && page.url().includes('account.booking.com/sign-in')) {
|
|
if (email && password && page.url().includes('account.booking.com/sign-in')) {
|
|
|
console.error('Session expired — attempting auto-login (headless)...');
|
|
console.error('Session expired — attempting auto-login (headless)...');
|
|
|
- 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 });
|
|
|
|
|
|
|
+ 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) {
|
|
} else if (FORCE_HEADLESS) {
|
|
|
await context.close();
|
|
await context.close();
|