(Created on )

Puppeteer: Prototype JSHandle must not be referencing primitive value

queryObjects receives a primitive rather than an object prototype handle.


queryObjects receives a primitive rather than an object prototype handle.

Error message

Prototype JSHandle must not be referencing primitive value

How this error happens

A number handle is a primitive value, not an object prototype. queryObjects requires a browser object reference.

The snippets use an open Puppeteer page named page.

const primitive = await page.evaluateHandle(() => {
    return 42;
});

await page.queryObjects(
    primitive
);

How to fix

Create a handle to the actual object prototype you want to query.

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

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

    await objects.dispose();
} finally {
    await prototype.dispose();
}

Things to keep in mind

Dispose the primitive handle from the failing example as well. Query results depend on which objects are currently retained in the browser heap.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →