(Created on )

Puppeteer: Timeout cleared

Deferred.race cancels a losing deferred's timer during cleanup.


Deferred.race cancels a losing deferred’s timer during cleanup.

Error message

Timeout cleared

How this error happens

Puppeteer’s internal race helper clears timers on losing deferred results. That cleanup rejects a losing deferred with “Timeout cleared”; it is not necessarily the main operation’s failure.

The snippets use an open page whose application will render either #ready or #error.

await Promise.race([
    page.waitForSelector("#ready"),
    page.waitForSelector("#error"),
]);

How to fix

Use public cancellation for application-level races and observe the winning operation, rather than treating a losing internal timer as the primary error.

const controller = new AbortController();

try {
    await Promise.race([
        page.waitForSelector("#ready", {
            signal: controller.signal,
        }),
        page.waitForSelector("#error", {
            signal: controller.signal,
        }),
    ]);
} finally {
    controller.abort();
}

Things to keep in mind

The page must render one of the two states. The first block illustrates a race with uncancelled losers; native Promise.race does not itself emit Puppeteer’s internal “Timeout cleared” message. If that message escapes as your top-level failure, preserve the winning error and stack.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →