(Created on )

Puppeteer: Page closed

A page was closed before a pending Puppeteer wait finished.


A page was closed before a pending Puppeteer wait finished.

Error message

Page closed!
Page closed.

How this error happens

Closing a page interrupts waits that depend on its future events. Here, no response can satisfy the waiter after the page is closed.

The snippets use an open Puppeteer page named page.

const waiting = page.waitForResponse(
    () => true
);

waiting.catch(() => { });

await page.close();

await waiting;

How to fix

Wait for the required response while the page is alive, and close the page only after consuming it.

const waiting = page.waitForResponse(
    (response) => {
        return response.url() === "https://example.com/";
    }
);

waiting.catch(() => { });

await page.goto(
    "https://example.com/"
);

const response = await waiting;

console.log(response.status());

await page.close();

Things to keep in mind

Run the corrected sequence with a new open page. Request, response and frame waits can use different punctuation: “Page closed!” or “Page closed.” A longer timeout cannot reopen a closed page.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →