Puppeteer: Cannot extract value when objectId is given
An internal value-extraction path received an object reference where a by-value result was expected.
An internal value-extraction path received an object reference where a by-value result was expected.
Error message
Cannot extract value when objectId is given
How this error happens
An internal primitive-value decoder expects a by-value result with no CDP object ID. A handle to an object instead has a reference ID.
The snippets use an open Chrome/CDP page named page. The correction continues with handle.
const handle = await page.evaluateHandle(() => {
return {
count: 3,
};
});
const remote = handle.remoteObject();
console.log(remote.objectId);
How to fix
Use jsonValue or evaluation to extract serializable data from the handle through the public API.
try {
const value = await handle.jsonValue();
console.log(value);
} finally {
await handle.dispose();
}
Things to keep in mind
The first snippet shows the reference-shaped input, not a direct invocation of the private primitive decoder. A correctly used public handle should route that input to the appropriate decoder automatically.