(Created on )

Puppeteer: Trying to evaluate JSHandle from different global types. Usually this means you're usin...

A BiDi JSHandle crosses incompatible page and worker global types.


A BiDi JSHandle crosses incompatible page and worker global types.

Error message

Trying to evaluate JSHandle from different global types. Usually this means you're usin...

How this error happens

A worker and a page have different global realms. Passing a worker handle into page evaluation crosses that boundary.

The snippets use a WebDriver BiDi page that already has a dedicated worker. The fix continues from the worker and handle created above.

const worker = page.workers()[0];

const handle = await worker.evaluateHandle(() => {
    return {
        count: 3,
    };
});

await page.evaluate(
    (value) => value.count,
    handle
);

How to fix

Read a plain value in the worker, then send that value to the page.

const count = await worker.evaluate(
    (value) => value.count,
    handle
);

await page.evaluate(
    (value) => {
        window.count = value;
    },
    count
);

Things to keep in mind

The worker must still be alive. Dispose handle after use. If the page has no worker, obtain one from your application’s worker event instead of indexing an empty array.

All Puppeteer errors

Keep Reading

Puppeteer Guides

All Guides →