Puppeteer: Trying to evaluate JSHandle from different frames. Usually this means you're using a ha...
A BiDi JSHandle belongs to a different frame/page environment.
A BiDi JSHandle belongs to a different frame/page environment.
Error message
Trying to evaluate JSHandle from different frames. Usually this means you're using a ha...
How this error happens
A handle belongs to the page and execution realm where it was created. A different page cannot use that reference as a local object.
The snippets use an open page and its running browser. The fix continues from the handles created before the failing call.
const otherPage = await browser.newPage();
const handle = await page.evaluateHandle(() => {
return {
count: 3,
};
});
await otherPage.evaluate(
(value) => value.count,
handle
);
How to fix
Evaluate the handle in its owning page. If the other page needs the data, transfer a plain value instead of a handle.
const count = await page.evaluate(
(value) => value.count,
handle
);
await otherPage.evaluate(
(value) => {
window.count = value;
},
count
);
Things to keep in mind
Close otherPage and dispose handle after use. CDP reports an execution-context mismatch; BiDi reports a frame mismatch. Separate frames in one page also have separate realms.