Runtime.evaluate returns an object id instead of its value
Categories
(Remote Protocol :: CDP, defect, P1)
Tracking
(firefox75 fixed)
Tracking | Status | |
---|---|---|
firefox75 | --- | fixed |
People
(Reporter: impossibus, Assigned: whimboo)
References
Details
(Whiteboard: [puppeteer-beta-mvp])
Attachments
(1 file)
417 bytes,
application/x-javascript
|
Details |
I noticed a differences in Runtime.evaluate
behaviour when running Puppeteer with Chrome and Firefox.
Excerpt of the script (see attached):
const page = await browser.newPage();
await page.goto('http://www.example.com');
console.log(await page.evaluate('Object.values(document.activeElement.classList)'));
The CDP command sent is:
method":"Runtime.evaluate","params":{"expression":"Object.values(document.activeElement.classList)\n//# sourceURL=__puppeteer_evaluation_script__","contextId":6442450946,"returnByValue":true,"awaitPromise":true,"userGesture":true}
Chrome returns:
"result":{"result":{"type":"object","value":[]}}
Firefox returns:
"result":{"result":{"objectId":"7877182c-3653-da40-9cb5-46ac3ab552b3","type":"object","subtype":"array"}}
and then hits an error in Puppeteer:
(node:49366) UnhandledPromiseRejectionWarning: Error: Cannot extract value when objectId is given
at assert (/Users/mfrydrychowicz/dev/puppeteer/lib/helper.js:283:11)
at Function.valueFromRemoteObject (/Users/mfrydrychowicz/dev/puppeteer/lib/helper.js:67:5)
at ExecutionContext._evaluateInternal (/Users/mfrydrychowicz/dev/puppeteer/lib/ExecutionContext.js:82:37)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async ExecutionContext.evaluate (/Users/mfrydrychowicz/dev/puppeteer/lib/ExecutionContext.js:48:12)
at async /Users/mfrydrychowicz/dev/puppeteer/examples/type.js:10:15
-- ASYNC --
at ExecutionContext.<anonymous> (/Users/mfrydrychowicz/dev/puppeteer/lib/helper.js:111:15)
at DOMWorld.evaluate (/Users/mfrydrychowicz/dev/puppeteer/lib/DOMWorld.js:112:20)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
-- ASYNC --
at Frame.<anonymous> (/Users/mfrydrychowicz/dev/puppeteer/lib/helper.js:111:15)
at Page.evaluate (/Users/mfrydrychowicz/dev/puppeteer/lib/Page.js:863:43)
at Page.<anonymous> (/Users/mfrydrychowicz/dev/puppeteer/lib/helper.js:112:23)
at /Users/mfrydrychowicz/dev/puppeteer/examples/type.js:10:26
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Reporter | ||
Comment 1•5 years ago
|
||
This is an example from the gutenberg tests so it should be in our alpha.
Reporter | ||
Comment 2•5 years ago
|
||
I should add that this is a problem whenever the script to evaluate returns an object. Returning a primitive works as expected.
The relevant code is at https://searchfox.org/mozilla-central/rev/131338e5017bc0283d86fb73844407b9a2155c98/remote/domains/content/runtime/ExecutionContext.jsm#358
Reporter | ||
Updated•5 years ago
|
Updated•5 years ago
|
Updated•5 years ago
|
Assignee | ||
Comment 3•5 years ago
|
||
Problem is that evaluate
doesn't check the returnByValue
property and always returns a remote object:
Adding a check for that and calling the _toRemoteObjectByValue
method as being added on bug 1615260 should fix that hopefully.
Assignee | ||
Comment 4•5 years ago
|
||
Maja, your example works fine for me now since bug 1615260 is fixed.
Updated•5 years ago
|
Updated•4 years ago
|
Description
•