Closed Bug 1597343 Opened 5 years ago Closed 5 years ago

Runtime.evaluate returns an object id instead of its value

Categories

(Remote Protocol :: CDP, defect, P1)

defect

Tracking

(firefox75 fixed)

RESOLVED FIXED
Firefox 75
Tracking Status
firefox75 --- fixed

People

(Reporter: impossibus, Assigned: whimboo)

References

Details

(Whiteboard: [puppeteer-beta-mvp])

Attachments

(1 file)

Attached file evaluate.js

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)

This is an example from the gutenberg tests so it should be in our alpha.

Priority: -- → P2
Whiteboard: [puppeteer-alpha]

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

Summary: Runtime.evaluate → Runtime.evaluate returns an object id instead of its value
Priority: P2 → P3
Whiteboard: [puppeteer-alpha] → [puppeteer-alpha-reserve]
Priority: P3 → P2
Whiteboard: [puppeteer-alpha-reserve] → [puppeteer-beta-mvp]
See Also: → 1614109

Problem is that evaluate doesn't check the returnByValue property and always returns a remote object:

https://searchfox.org/mozilla-central/rev/a4be2fbe9bd4f405c91cc16e4e3a80400f5a9301/remote/domains/content/runtime/ExecutionContext.jsm#97-99

Adding a check for that and calling the _toRemoteObjectByValue method as being added on bug 1615260 should fix that hopefully.

Depends on: 1615260

Maja, your example works fine for me now since bug 1615260 is fixed.

Assignee: nobody → hskupin
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 75
Priority: P2 → P1
Component: CDP: Runtime → CDP
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: