Browse Source

fix: detect add-phone after login and sleep 30s before next run

Only Step 5 (signup) should see add-phone page. If it appears after
Step 6 (login), treat as failure, sleep 30s, then continue next run.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
chendeben 4 tháng trước cách đây
mục cha
commit
f8c4a01eef
1 tập tin đã thay đổi với 21 bổ sung15 xóa
  1. 21 15
      background.js

+ 21 - 15
background.js

@@ -1006,6 +1006,20 @@ async function autoRunLoop(totalRuns) {
       await executeStepAndWait(4, 2000);
       await executeStepAndWait(5, 3000);
       await executeStepAndWait(6, 3000);
+
+      // After login, check if page landed on add-phone again (not normal after step 5)
+      const phoneCheckTabId = await getTabId('signup-page');
+      if (phoneCheckTabId) {
+        try {
+          const phoneTab = await chrome.tabs.get(phoneCheckTabId);
+          if (phoneTab.url && (phoneTab.url.includes('add-phone') || phoneTab.url.includes('/phone'))) {
+            throw new Error('PHONE_VERIFY_REQUIRED');
+          }
+        } catch (e) {
+          if (e.message === 'PHONE_VERIFY_REQUIRED') throw e;
+        }
+      }
+
       await executeStepAndWait(7, 2000);
       await executeStepAndWait(8, 2000);
       await executeStepAndWait(9, 1000);
@@ -1020,9 +1034,14 @@ async function autoRunLoop(totalRuns) {
         break; // Only stop on explicit user stop
       } else {
         failCount++;
-        await addLog(`Run ${run}/${totalRuns} failed: ${err.message} (${successCount} succeeded, ${failCount} failed)`, 'error');
+        if (err.message === 'PHONE_VERIFY_REQUIRED') {
+          await addLog(`Run ${run}/${totalRuns} failed: Phone verification required — sleeping 30s before next run (${successCount} succeeded, ${failCount} failed)`, 'error');
+          await sleepWithStop(30000);
+        } else {
+          await addLog(`Run ${run}/${totalRuns} failed: ${err.message} (${successCount} succeeded, ${failCount} failed)`, 'error');
+        }
         await addLog(`Skipping to next run...`, 'warn');
-        continue; // Continue to next run on error
+        continue;
       }
     }
   }
@@ -1480,19 +1499,6 @@ async function executeStep6(state) {
 // ============================================================
 
 async function executeStep7(state) {
-  // Check if page landed on add-phone — means phone verification required, skip this run
-  const signupTabIdCheck = await getTabId('signup-page');
-  if (signupTabIdCheck) {
-    try {
-      const tab = await chrome.tabs.get(signupTabIdCheck);
-      if (tab.url && (tab.url.includes('add-phone') || tab.url.includes('/phone'))) {
-        throw new Error('Phone verification required — skipping this account.');
-      }
-    } catch (err) {
-      if (err.message.includes('Phone verification')) throw err;
-    }
-  }
-
   // Check if the page is on /about-you (birthday not filled during signup)
   // and handle it before proceeding with verification code polling
   try {