From d2480b022d74b7071b515408a31c6e82448e3c9e Mon Sep 17 00:00:00 2001 From: Nikolay Vitkov <34244704+Lightning00Blade@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:38:27 +0100 Subject: [PATCH] fix: better debugging for WaitTask (#11330) --- packages/puppeteer-core/src/common/WaitTask.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/puppeteer-core/src/common/WaitTask.ts b/packages/puppeteer-core/src/common/WaitTask.ts index 9392d05f68a..ad50fce89c4 100644 --- a/packages/puppeteer-core/src/common/WaitTask.ts +++ b/packages/puppeteer-core/src/common/WaitTask.ts @@ -48,6 +48,7 @@ export class WaitTask { #args: unknown[]; #timeout?: NodeJS.Timeout; + #timeoutError?: TimeoutError; #result = Deferred.create>(); @@ -88,10 +89,11 @@ export class WaitTask { this.#world.taskManager.add(this); if (options.timeout) { + this.#timeoutError = new TimeoutError( + `Waiting failed: ${options.timeout}ms exceeded` + ); this.#timeout = setTimeout(() => { - void this.terminate( - new TimeoutError(`Waiting failed: ${options.timeout}ms exceeded`) - ); + void this.terminate(this.#timeoutError); }, options.timeout); } @@ -184,9 +186,7 @@ export class WaitTask { async terminate(error?: Error): Promise { this.#world.taskManager.delete(this); - if (this.#timeout) { - clearTimeout(this.#timeout); - } + clearTimeout(this.#timeout); if (error && !this.#result.finished()) { this.#result.reject(error);