Avoid reloading the page in case of error

This commit is contained in:
ngosang 2021-10-20 18:06:15 +02:00
parent 1e463bb3e2
commit a79a5f2b42

View File

@ -82,15 +82,17 @@ async function resolveChallenge(params: V1Request, session: SessionsCacheItem):
// detect protection services and solve challenges
try {
response = await cloudflareProvider(params.url, page, response);
// is response is ok
// reload the page to be sure we get the real page
log.debug("Reloading the page")
response = await gotoPage(params, page);
} catch (e) {
status = "error";
message = "Cloudflare " + e.toString();
}
// reload the page to be sure we get the real page
log.debug("Reloading the page")
response = await gotoPage(params, page);
const payload: ChallengeResolutionT = {
status,
message,
@ -131,7 +133,7 @@ async function gotoPage(params: V1Request, page: Page): Promise<Response> {
} else {
// post hack
// first request a page without cloudflare
response = await page.goto("https://www.google.com", {waitUntil: 'domcontentloaded'});
response = await page.goto(params.url, {waitUntil: 'domcontentloaded'});
await page.setContent(
`
<!DOCTYPE html>