Sfoglia il codice sorgente

fix: handle remembered-account screen in Airbnb auto-login

A device-remembered session with no live cookies shows neither the
#phone-or-email input nor #password directly — the username step is
skipped and the same submit button the cold flow uses is already
clickable. Detect this as a fallback when the warm/cold race times out
(submit button visible, #phone-or-email not), click it without filling
email, and merge into the cold flow's existing post-submit path.
ZiB 5 giorni fa
parent
commit
fea850b546
1 ha cambiato i file con 21 aggiunte e 6 eliminazioni
  1. 21 6
      room_cal/service_api/typescript/airbnb/refresh-cookies.ts

+ 21 - 6
room_cal/service_api/typescript/airbnb/refresh-cookies.ts

@@ -57,19 +57,34 @@ async function performLogin(page: Page, email: string, password: string): Promis
   await page.waitForLoadState('domcontentloaded');
 
   // Detect warm (password page shown immediately) vs cold (email input first).
-  const flow = await Promise.race([
+  let flow: 'warm' | 'cold' | 'remembered' | null = await Promise.race([
     page.waitForSelector('#password', { timeout: 15_000 }).then(() => 'warm' as const),
     page.waitForSelector('#phone-or-email', { timeout: 15_000 }).then(() => 'cold' as const),
   ]).catch(() => null);
 
   if (!flow) {
-    loginDisabledReason = 'neither email input nor password field appeared on signup_login';
-    throw new Error(`[airbnb] ${loginDisabledReason}`);
+    // Neither field appeared — check for the remembered-account screen: the device is
+    // recognized, so #phone-or-email is skipped entirely and the same submit button that
+    // the cold flow fills-then-clicks is shown ready to click immediately. Everything after
+    // the click is identical to the cold flow (Try another way → password option).
+    const submitBtn = page.locator('button[type="submit"]');
+    const remembered = await submitBtn.isVisible().catch(() => false)
+      && !(await page.locator('#phone-or-email').isVisible().catch(() => false));
+    if (remembered) {
+      flow = 'remembered';
+    } else {
+      loginDisabledReason = 'neither email input nor password field appeared on signup_login';
+      throw new Error(`[airbnb] ${loginDisabledReason}`);
+    }
   }
 
-  if (flow === 'cold') {
-    console.error('[airbnb] Auto-login: cold session — filling email...');
-    await page.locator('#phone-or-email').fill(email);
+  if (flow === 'cold' || flow === 'remembered') {
+    if (flow === 'cold') {
+      console.error('[airbnb] Auto-login: cold session — filling email...');
+      await page.locator('#phone-or-email').fill(email);
+    } else {
+      console.error('[airbnb] Auto-login: remembered-account session — skipping email entry...');
+    }
     await page.locator('button[type="submit"]').click();
 
     const tryAnother = page.getByRole('button', { name: /try another way/i });