Search code examples
c#puppeteer-sharp

How to await an async function evaluation in PuppeteerSharp


In Puppeteer you can evaluate async functions:

await page.evaluate(async () => {
    // await some promise
});

Is there an equivalent in PuppeteerSharp? Using EvaluateFunctionAsync, the task completes before the promise resolves:

await page.EvaluateFunctionAsync(@"async () => {
    // await some promise
}");

Solution

  • That's the right way, for example:

    var six = await page.EvaluateFunctionAsync<int>("async () => await Promise.resolve(6)");