(step, timeout = 45000)
| 196 | } |
| 197 | |
| 198 | async function resendVerificationCode(step, timeout = 45000) { |
| 199 | if (step === 7) { |
| 200 | await waitForLoginVerificationPageReady(); |
| 201 | } |
| 202 | |
| 203 | const start = Date.now(); |
| 204 | let action = null; |
| 205 | let loggedWaiting = false; |
| 206 | |
| 207 | while (Date.now() - start < timeout) { |
| 208 | throwIfStopped(); |
| 209 | |
| 210 | // Check for 405 error page and recover by clicking "Try again" |
| 211 | if (is405MethodNotAllowedPage()) { |
| 212 | await handle405ResendError(step, timeout - (Date.now() - start)); |
| 213 | // After recovery, loop back to find the resend button again |
| 214 | loggedWaiting = false; |
| 215 | continue; |
| 216 | } |
| 217 | |
| 218 | action = findResendVerificationCodeTrigger({ allowDisabled: true }); |
| 219 | |
| 220 | if (action && isActionEnabled(action)) { |
| 221 | log(`步骤 ${step}:重新发送验证码按钮已可用。`); |
| 222 | await humanPause(350, 900); |
| 223 | simulateClick(action); |
| 224 | await sleep(1200); |
| 225 | |
| 226 | // After clicking resend, check if 405 error appeared |
| 227 | if (is405MethodNotAllowedPage()) { |
| 228 | log(`步骤 ${step}:点击重新发送后出现 405 错误,正在恢复...`, 'warn'); |
| 229 | await handle405ResendError(step, timeout - (Date.now() - start)); |
| 230 | loggedWaiting = false; |
| 231 | continue; |
| 232 | } |
| 233 | |
| 234 | return { |
| 235 | resent: true, |
| 236 | buttonText: getActionText(action), |
| 237 | }; |
| 238 | } |
| 239 | |
| 240 | if (action && !loggedWaiting) { |
| 241 | loggedWaiting = true; |
| 242 | log(`步骤 ${step}:正在等待重新发送验证码按钮变为可点击...`); |
| 243 | } |
| 244 | |
| 245 | await sleep(250); |
| 246 | } |
| 247 | |
| 248 | throw new Error('无法点击重新发送验证码按钮。URL: ' + location.href); |
| 249 | } |
| 250 | |
| 251 | function is405MethodNotAllowedPage() { |
| 252 | const pageText = document.body?.textContent || ''; |
no test coverage detected