Emtiaz Abrar
Emtiaz Abrar

Reputation: 31

how to make page wait till the navigation is not completed in puppeteer

Here is my scenario:

My app uses Azure authentication, so it's setup such a way that when i say await page.goto(url,{waitUntil:'condition'}) - it opens the app in a new tab and then it opens a new window which gets the authentication token and closes itself and comes back to the main app page.

Now the problem is the moment this new page opens, puppeteer thinks the execution of this await page.goto(url,{waitUntil:'condition', timeout:60000}) line is done. So it jumps to next line, even though my app has not been loaded yet. I am not sure how can get the instance of the main app page and make it wait until the navigation completes. So i tried the below option, i tried to make all the opened page instances waitForNavigation:

pages = await browser.pages(
pages.forEach(page => {
   await page.waitForNavigation({waitUntil: 'networkidle0', timeout: 60000}) 
})

-This didn't work as well.

Please let me know how can i make the parent page/the page which has my main app waits until the other tab gets the token back to it.

~tia

Upvotes: 1

Views: 527

Answers (1)

Andrea Bisello
Andrea Bisello

Reputation: 1225

if you cannot store the login token in the actual page, maybe received as a callback function,

maybe you can make something using

to

  • wait until browser has 2 tabs
  • wait until one of the page is the login page
  • wait until browser has 1 tab (because the login page answered)
  • continue.

if you can check the existence of the token in page,

simply make a while and wait until token has a value.

Upvotes: 1

Related Questions