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
What to do with page.evaluateAsync
?
#11
Comments
Guys, I would appreciate your feedback on this! cc @ebidel @paulirish @dgozman |
FWIW, from our experience w/ Lighthouse, lots of the code we've needed to eval in the page needs to be wrapped in a promise. Basically, anything non-trivial the user will be doing. Also, most of the web platform APIs have moved towards promises, so devs are used to dealing with them. I like the idea of one method. Simplify + keep things async. Though, do we want to match the Phantom API as much as possible? It might be easier to transition existing users. |
Phantom's evaluateAsync is a totally different beast, (which is not needed in our case since most of puppeteer's api's return promises). This is a good argument towards removing puppeteer's
I think we want to strike a good balance between having a familiar API while not missing the opportunity to improve. So if there are a few options to implement X and there is no clear winner, we should pick the one which is more familiar for phantom users. |
Today, there are two methods in page's API:
page.evaluate
which evaluates code in the page and returns result.page.evaluateAync
which too evaluates code in the page and, if the evaluation result is promise, waits for promise to resolve and returns the promise value.The
page.evaluate
is straightforward, butpage.evaluateAsync
has cryptic name and hard to grasp. Should we remove thepage.evaluateAsync
and always await promise inpage.evaluate
?If we want to keep them separate, is there a better name for the
page.evaluateAsync
?Illustrating with examples, the following snippet returns "42":
However, if we try to return a promise, we will get an empty object as a result:
In order to get the '42' as a returned value, one would need to use
page.evaluateAsync
:This kind of situation could be avoided if we were to await promise in
page.evaluate
.For the record: in case of merging
evaluate
with theevaluateAsync
methods, we should make sure that evaluating the code from-inside the inpagecallback works successfully (which is a bit tricky since page is on a pause)The text was updated successfully, but these errors were encountered: