(Created on )

Puppeteer: Prototype JSHandle is disposed!

queryObjects receives a disposed prototype JSHandle.


queryObjects receives a disposed prototype JSHandle.

Error message

Prototype JSHandle is disposed!

How this error happens

queryObjects needs a live prototype handle. A disposed handle cannot identify the prototype in the browser heap.

The snippets use an open Puppeteer page named page.

const prototype = await page.evaluateHandle(() => {
    return Array.prototype;
});

await prototype.dispose();

await page.queryObjects(
    prototype
);

How to fix

Keep the prototype alive while querying, then dispose both the query result and the prototype.

const prototype = await page.evaluateHandle(() => {
    return Array.prototype;
});

try {
    const objects = await page.queryObjects(
        prototype
    );

    try {
        const count = await objects.evaluate(
            (items) => items.length
        );

        console.log(count);
    } finally {
        await objects.dispose();
    }
} finally {
    await prototype.dispose();
}

Things to keep in mind

The browser/protocol must support queryObjects. This is a heap query, not a selector query.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →