Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluate returns undefined but chromium correctly has value inside evaluate #2418

Closed
chrisabrams opened this issue Apr 19, 2018 · 7 comments
Closed

Comments

@chrisabrams
Copy link

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.3.0
  • Platform / OS version: OS X Sierra 10.12.6
  • URLs (if applicable):
  • Node.js version: 8.10.0

What steps will reproduce the problem?

You can run this gist here: https://gist.github.com/chrisabrams/a2a098d1b2d697f349f4e1ad1be98602

What is the expected result?
The expected result is that evaluate will return the list of nodes

What happens instead?
Instead, evaluate returns undefined

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 19, 2018

If I get this right, DevTools protocol cannot serialize an array of nodes and resolves it to undefined. If you make it an array of strings, this works:

return nodes.map(({ innerText }) => innerText)

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 19, 2018

See in the doc:

If the function passed to the page.evaluate returns a non-Serializable value, then page.evaluate resolves to undefined.

@yanivefraim
Copy link
Contributor

yanivefraim commented Apr 19, 2018

How about throwing an error when evaluate returns a non-Serializable value? cc @aslushnikov

@chrisabrams
Copy link
Author

Got it @vsemozhetbyt. I would concur on adding a error when the value being returned is not serializable.

@aslushnikov
Copy link
Contributor

@yanivefraim @chrisabrams we were there at one moment, but had to change to undefined because there are many evaluations that happen for the sake of evaluation rather then return value.

await page.evaluate(() => window.saveValue = document.body);

We consider returning a special value in this case instead to emphasize the difference.

@chrisabrams
Copy link
Author

@aslushnikov I see what you're saying. In my case, I need to know the saveValue outside of the evaluation. I can make serialization work though.

@aslushnikov
Copy link
Contributor

In my case, I need to know the saveValue outside of the evaluation. I can make serialization work though.

@chrisabrams why don't you use the page.evaluateHandle then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants