Set puppeteer timeout half of maxTimeout param. Resolves #180

This commit is contained in:
ngosang
2021-10-20 18:28:30 +02:00
parent a6628d0cda
commit 753e8e1be8
3 changed files with 14 additions and 4 deletions

View File

@@ -24,13 +24,12 @@ export interface ChallengeResolutionT {
}
async function resolveChallengeWithTimeout(params: V1Request, session: SessionsCacheItem) {
const maxTimeout = params.maxTimeout || 60000
const timer = new Timeout();
try {
const promise = resolveChallenge(params, session);
return await Promise.race([
promise,
timer.set(maxTimeout, `Maximum timeout reached. maxTimeout=${maxTimeout} (ms)`)
timer.set(params.maxTimeout, `Maximum timeout reached. maxTimeout=${params.maxTimeout} (ms)`)
]);
} finally {
timer.clear();
@@ -44,6 +43,10 @@ async function resolveChallenge(params: V1Request, session: SessionsCacheItem):
const page: Page = await session.browser.newPage()
// the Puppeter timeout should be half the maxTimeout because we reload the page and wait for challenge
// the user can set a really high maxTimeout if he wants to
await page.setDefaultNavigationTimeout(params.maxTimeout / 2)
// the user-agent is changed just for linux arm build
await page.setUserAgent(sessions.getUserAgent())