Fix ban detection. Resolves #330 (#336)

This commit is contained in:
Harold 2022-03-19 05:24:49 +01:00 committed by GitHub
parent c951ba2523
commit bb4fa9cabc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,7 +37,13 @@ export default async function resolveChallenge(url: string, page: Page, response
}
if (await findAnySelector(page, BAN_SELECTORS)) {
throw new Error('Cloudflare has blocked this request. Probably your IP is banned for this site, check in your web browser.')
const errorCodeElem = await page.$(BAN_SELECTORS[0]);
if (errorCodeElem) {
let displayCSSProperty = await errorCodeElem.evaluate(el => (<HTMLElement>el).style.display);
if (displayCSSProperty !== 'none') {
throw new Error('Cloudflare has blocked this request. Probably your IP is banned for this site, check in your web browser.');
}
}
}
// find Cloudflare selectors