(tabId, baselineUrl, timeoutMs = STEP8_CLICK_EFFECT_TIMEOUT_MS)
| 6156 | } |
| 6157 | |
| 6158 | async function waitForStep8ClickEffect(tabId, baselineUrl, timeoutMs = STEP8_CLICK_EFFECT_TIMEOUT_MS) { |
| 6159 | const start = Date.now(); |
| 6160 | let recovered = false; |
| 6161 | |
| 6162 | while (Date.now() - start < timeoutMs) { |
| 6163 | throwIfStopped(); |
| 6164 | |
| 6165 | const tab = await chrome.tabs.get(tabId).catch(() => null); |
| 6166 | if (!tab) { |
| 6167 | throw new Error('步骤 8:认证页面标签页已关闭,无法继续自动授权。'); |
| 6168 | } |
| 6169 | |
| 6170 | if (baselineUrl && typeof tab.url === 'string' && tab.url !== baselineUrl) { |
| 6171 | return { progressed: true, reason: 'url_changed', url: tab.url }; |
| 6172 | } |
| 6173 | |
| 6174 | const pageState = await getStep8PageState(tabId); |
| 6175 | if (pageState?.addPhonePage) { |
| 6176 | throw new Error('步骤 8:点击“继续”后页面跳到了手机号页面,当前流程无法继续自动授权。'); |
| 6177 | } |
| 6178 | if (pageState === null) { |
| 6179 | if (!recovered) { |
| 6180 | recovered = true; |
| 6181 | await ensureStep8SignupPageReady(tabId, { |
| 6182 | timeoutMs: Math.max(3000, Math.min(8000, timeoutMs)), |
| 6183 | logMessage: '步骤 8:点击后认证页正在重载,正在等待内容脚本重新就绪...', |
| 6184 | }).catch(() => null); |
| 6185 | continue; |
| 6186 | } |
| 6187 | await sleepWithStop(200); |
| 6188 | continue; |
| 6189 | } |
| 6190 | recovered = false; |
| 6191 | |
| 6192 | await sleepWithStop(200); |
| 6193 | } |
| 6194 | |
| 6195 | return { progressed: false, reason: 'no_effect' }; |
| 6196 | } |
| 6197 | |
| 6198 | function getStep8EffectLabel(effect) { |
| 6199 | switch (effect?.reason) { |
no test coverage detected