This commit is contained in:
dengqichen 2025-11-16 21:15:06 +08:00
parent 5d1d4e51ac
commit 774a6c118a

View File

@ -341,37 +341,78 @@ class WindsurfRegister {
// 如果验证通过点击Continue按钮进入下一页 // 如果验证通过点击Continue按钮进入下一页
if (result === 'passed') { if (result === 'passed') {
logger.info(this.siteName, '[Cloudflare] 点击Continue按钮进入验证码页面...'); logger.info(this.siteName, '[Cloudflare] 点击Continue按钮进入验证码页面...');
try { try {
const currentUrl = this.page.url(); let pageChanged = false;
const button = await this.page.$('button:not([disabled])'); let attempts = 0;
if (button) { const maxAttempts = 10; // 最多尝试10次
await button.click();
// 等待页面跳转或内容改变 while (!pageChanged && attempts < maxAttempts) {
try { attempts++;
// 方法1: 等待URL改变
await this.page.waitForFunction( // 查找并点击Continue按钮
(oldUrl) => window.location.href !== oldUrl, const button = await this.page.$('button:not([disabled])');
{ timeout: 10000 }, if (button) {
currentUrl logger.info(this.siteName, `[Cloudflare] 第${attempts}次点击Continue...`);
); await button.click();
logger.success(this.siteName, '[Cloudflare] 页面已跳转'); await this.human.randomDelay(2000, 3000);
} catch (e) {
// 方法2: 如果URL没变等待"Check your inbox"文本出现 // 检查是否有错误提示
try { const hasError = await this.page.evaluate(() => {
await this.page.waitForFunction( const errorMsg = document.querySelector('p.caption1.text-sk-error');
() => document.body.textContent.includes('Check your inbox'), return errorMsg && errorMsg.textContent.includes('An error occurred');
{ timeout: 5000 } });
);
logger.success(this.siteName, '[Cloudflare] 验证码页面已加载'); if (hasError) {
} catch (e2) { logger.warn(this.siteName, '[Cloudflare] 检测到错误提示,重新尝试...');
logger.warn(this.siteName, '[Cloudflare] 等待页面改变超时,继续...'); await this.human.randomDelay(2000, 3000);
continue;
} }
}
// 额外等待确保页面稳定 // 检查页面是否已改变
await this.human.randomDelay(2000, 3000); const checkResult = await this.page.evaluate(() => {
// 方法1: 检查是否有"Check your inbox"文本
const hasCheckInbox = document.body.textContent.includes('Check your inbox');
// 方法2: 检查按钮是否被禁用
const button = document.querySelector('button');
const buttonDisabled = button && button.disabled;
// 方法3: 检查是否还有"verify that you are human"文本
const stillOnVerifyPage = document.body.textContent.includes('verify that you are human');
return {
hasCheckInbox,
buttonDisabled,
stillOnVerifyPage
};
});
logger.info(this.siteName, `[Cloudflare] 页面状态: inbox=${checkResult.hasCheckInbox}, buttonDisabled=${checkResult.buttonDisabled}, stillVerify=${checkResult.stillOnVerifyPage}`);
// 判断是否成功跳转
if (checkResult.hasCheckInbox || (!checkResult.stillOnVerifyPage && checkResult.buttonDisabled)) {
pageChanged = true;
logger.success(this.siteName, '[Cloudflare] ✓ 已进入验证码页面');
break;
}
// 如果还在验证页面,继续等待
logger.info(this.siteName, '[Cloudflare] 页面未跳转,继续尝试...');
await this.human.randomDelay(2000, 3000);
} else {
logger.warn(this.siteName, '[Cloudflare] 未找到可点击的按钮');
break;
}
} }
if (!pageChanged) {
logger.warn(this.siteName, `[Cloudflare] ${maxAttempts}次尝试后页面仍未跳转`);
}
// 额外等待确保页面稳定
await this.human.randomDelay(2000, 3000);
} catch (e) { } catch (e) {
logger.warn(this.siteName, `[Cloudflare] 点击按钮失败: ${e.message}`); logger.warn(this.siteName, `[Cloudflare] 点击按钮失败: ${e.message}`);
} }