fix: Robust Cloudflare detection to prevent Playwright frame crashes
- src/cloudflare.js: Add try-catch around each locator operation in isCloudflareChallenge - src/cloudflare.js: Add waitForLoadState before checking for Cloudflare - src/cloudflare.js: Remove redundant outer try-catch (unreachable code) - epic-claimer-new.js: Add delay after page.goto before checking Cloudflare - epic-claimer-new.js: Wrap isChallenge() call in try-catch Fixes: TypeError: Cannot read properties of undefined (reading 'childFrames')
This commit is contained in:
parent
23ca522094
commit
f1d647bcb2
2 changed files with 37 additions and 14 deletions
|
|
@ -183,16 +183,24 @@ const ensureLoggedIn = async (page, context) => {
|
||||||
if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout);
|
if (!cfg.debug) context.setDefaultTimeout(cfg.login_timeout);
|
||||||
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
|
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
|
||||||
|
|
||||||
if (await isChallenge()) {
|
// Small delay to let page stabilize before checking for Cloudflare
|
||||||
console.warn('Cloudflare challenge detected. Attempting to solve with FlareSolverr...');
|
await page.waitForTimeout(1000);
|
||||||
const solved = await solveCloudflareChallenge();
|
|
||||||
if (solved) {
|
try {
|
||||||
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
|
if (await isChallenge()) {
|
||||||
|
console.warn('Cloudflare challenge detected. Attempting to solve with FlareSolverr...');
|
||||||
|
const solved = await solveCloudflareChallenge();
|
||||||
|
if (solved) {
|
||||||
|
await page.goto(URL_CLAIM, { waitUntil: 'domcontentloaded' });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await notify('epic-games (new): Cloudflare challenge, please solve manually in browser.');
|
||||||
|
await page.waitForTimeout(cfg.login_timeout);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
await notify('epic-games (new): Cloudflare challenge, please solve manually in browser.');
|
} catch (err) {
|
||||||
await page.waitForTimeout(cfg.login_timeout);
|
console.warn('Error checking Cloudflare challenge:', err.message);
|
||||||
continue;
|
// Continue with login attempt anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
const logged = await attemptAutoLogin();
|
const logged = await attemptAutoLogin();
|
||||||
|
|
|
||||||
|
|
@ -99,29 +99,44 @@ export const solveCloudflare = async (page, url) => {
|
||||||
* @returns {Promise<boolean>} - True if Cloudflare challenge is detected
|
* @returns {Promise<boolean>} - True if Cloudflare challenge is detected
|
||||||
*/
|
*/
|
||||||
export const isCloudflareChallenge = async page => {
|
export const isCloudflareChallenge = async page => {
|
||||||
|
// Wait for page to be in a stable state before checking
|
||||||
|
try {
|
||||||
|
await page.waitForLoadState('domcontentloaded', { timeout: 5000 });
|
||||||
|
} catch {
|
||||||
|
// Page might still be loading, continue anyway
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for Cloudflare iframe - wrap in try-catch to avoid frame race conditions
|
||||||
try {
|
try {
|
||||||
// Check for Cloudflare iframe
|
|
||||||
const cfFrame = page.locator('iframe[title*="Cloudflare"], iframe[src*="challenges"]');
|
const cfFrame = page.locator('iframe[title*="Cloudflare"], iframe[src*="challenges"]');
|
||||||
if (await cfFrame.count() > 0) {
|
if (await cfFrame.count() > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// Frame access failed, ignore
|
||||||
|
}
|
||||||
|
|
||||||
// Check for Cloudflare text
|
// Check for Cloudflare text - wrap in try-catch
|
||||||
|
try {
|
||||||
const cfText = page.locator('text=Verify you are human, text=Checking your browser');
|
const cfText = page.locator('text=Verify you are human, text=Checking your browser');
|
||||||
if (await cfText.count() > 0) {
|
if (await cfText.count() > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} catch {
|
||||||
|
// Locator failed, ignore
|
||||||
|
}
|
||||||
|
|
||||||
// Check for specific Cloudflare URLs
|
// Check for specific Cloudflare URLs
|
||||||
|
try {
|
||||||
const url = page.url();
|
const url = page.url();
|
||||||
if (url.includes('cloudflare') || url.includes('challenges')) {
|
if (url.includes('cloudflare') || url.includes('challenges')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
} catch {
|
} catch {
|
||||||
return false;
|
// URL access failed, ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue