diff --git a/packages/puppeteer-core/src/common/WaitTask.ts b/packages/puppeteer-core/src/common/WaitTask.ts index 720f7e64..f08d6936 100644 --- a/packages/puppeteer-core/src/common/WaitTask.ts +++ b/packages/puppeteer-core/src/common/WaitTask.ts @@ -177,10 +177,11 @@ export class WaitTask { async terminate(error?: unknown): Promise { this.#world.taskManager.delete(this); + if (this.#timeout) { + clearTimeout(this.#timeout); + } + if (error && !this.#result.finished()) { - if (this.#timeout) { - clearTimeout(this.#timeout); - } this.#result.reject(error); }