Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Puppeteer: How to use promise in evaluate?

Tags:

puppeteer

var wait = await page3.evaluate(()=> {
    $('.modal').hide()
    setTimeout(()=>{
      return true
    }, 3000);
});

Ex: wait 3 second in evaulate

like image 392
yarek Avatar asked Dec 02 '17 22:12

yarek


1 Answers

You return a promise and resolve it when you want. Returning a promise will make it wait until it's resolved.

var wait = await page3.evaluate(()=> {
 return new Promise((resolve,reject)=>{
    $('.modal').hide()
    setTimeout(()=>{
      resolve(true)
    }, 3000);
 });
});
like image 56
Md. Abu Taher Avatar answered Sep 25 '22 20:09

Md. Abu Taher