question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

page.waitForNavigation never resolves

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 1.8.0
  • Platform / OS version: MacOSX High Sierra
  • URLs (if applicable):
  • Node.js version: 10.0.0

What steps will reproduce the problem?

const http = require('http')
const puppeteer = require('puppeteer')
const PORT = 3000

/**
 * Dummy HTTP Server
 */
http.createServer((req, res) => {
  if (req.url === '/there') {
  	console.log('Responded')
    res.writeHead(200, { 'content-type': 'text/plain' })
    res.end('reached there')
  } else {
    res.writeHead(200, { 'content-type': 'text/html' })
    res.end(`
      <a href="/there"> Redirect </a>
    `)
  }
}).listen(PORT)

/**
 * Puppeteer script
 */
async function run () {
	const browser = await puppeteer.launch()
	const page = await browser.newPage()
	await page.goto('http://localhost:3000')
	await page.click('a')
	await page.waitForNavigation()

	const text = await page.evaluate(() => document.body.innerText)
	console.log(text)
}

run().then(console.log).catch(console.log)

What is the expected result? To see the text on console

What happens instead? page.waitForNavigation is stuck and then times out after 30 seconds

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

45reactions
ntzmcommented, Oct 3, 2018

You’re experiencing a race condition. Try using the example code instead:

const navigationPromise = page.waitForNavigation();
await page.click('a.my-link'); // Clicking the link will indirectly cause a navigation
await navigationPromise; // The navigationPromise resolves after navigation has finished
24reactions
vsemozhetbytcommented, Oct 3, 2018

Or you can use this way:

await Promise.all([page.click('a'), page.waitForNavigation()]);
Read more comments on GitHub >

github_iconTop Results From Across the Web

waitForNavigation hanging, even though page was loaded
According to Puppeteer documentation proper pattern for clicking on submit and waiting for navigation is like this: await Promise.all([ page ...
Read more >
puppeteer.Page.waitForNavigation JavaScript and Node.js ...
Promise which resolves to a new Page object. Page.goto. Navigates to a URL. Browser.close. Closes browser with all the pages (if any were...
Read more >
Navigating & waiting - Checkly
You can use Puppeteer's page.waitForNavigation() method here to explicitly wait for this event to happen and then continue your script.
Read more >
Page.waitForNavigation() method - Puppeteer
A Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the...
Read more >
How to make puppeteer wait for page to load - Urlbox
waitForNavigation and wait for these events to fire. waitUntil: domcontentloaded. The domcontentloaded option will fire the earliest, and is the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found