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.

Clicking and waiting for navigation is flaky in 0.13

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 0.13.0
  • Platform / OS version: macOS / 10.13.2
  • Node: 8.9.0

What steps will reproduce the problem?

We replaced casperjs tests with jest+puppeteer and in multiple tests we use click+waitForNavigation combo. This worked fine in 0.12, but it seems to be broken in 0.13.

Minimal example:

const puppeteer = require('puppeteer');

async function main() {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  page.on('load', () => console.log('loaded!'));

  await page.goto('https://mdn.github.io/learning-area/html/forms/your-first-HTML-form/first-form-styled.html');
  await page.waitForSelector('form[action^="/my-handling-form-page"]');
  await page.type('input[name="user_mail"]', 'mati@mati.com');
  await page.type('input[name="user_name"]', 'mati');

  await page.click('button[type="submit"]');
  console.log('clicked');

  await page.waitForNavigation();

  console.log('done');
}

main();

What is the expected result? Console should say (as it does every time in 0.12):

loaded!
clicked
loaded!
done

What happens instead? Most of the time (not always!) console says:

loaded!
loaded!
clicked
(node:31100) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Navigation Timeout Exceeded:30000ms exceeded

Seems to be reproducible in try-puppeteer (although happens less often than on my machine) screen shot 2017-12-20 at 23 44 55

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

8reactions
aslushnikovcommented, Jan 4, 2018

@kdzwinel the waitForNavigation is in fact a waitForNextNavigation. Puppeteer lives out-of-process to chrome, so the “next navigation” is a racy concept.

If you’re sure that page is not navigating somewhere and that click spawns a navigation, I’d use the following pattern to click-and-wait-for-navigation:

await Promise.all([
  page.click('button[type="submit"]'),
  page.waitForNavigation(),
]);

Generally, as @xprudhomme mentioned, the waitForSelector gives much better guarantees about page state then waitForNavigation.

6reactions
mathurscommented, May 11, 2018

We need a generic way to check the page url after a click event where the click may or may not navigate. Having to know beforehand is a bummer and in this case waitForSelector can’t be used.

Is there anyway we can know if there are active network request or to check the readyState of the document. That would really help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Selenium build unstable in Jenkins but fine locally
However, I still have some that pass locally but will be flaky on certain things. I noticed it always happens at waits. For...
Read more >
playwright-chromium - UNPKG
139, * would wait for the promise to resolve and return its value. ... 1501, * first click of the `dblclick()` triggers a...
Read more >
try - Mercurial - Mozilla
waitForNavigation should fail when frame detaches (navigation.spec.ts)": ... 'Headless Chrome'); // Wait for suggest overlay to appear and click "show all ...
Read more >
Chapter 11: Interim Controls - HUD
www.energystar.gov (click on the “Find ENERGY STAR Products” or similar hotlink). ... Loose and flaking paint should be carefully scraped away, and repairs ......
Read more >
Motivations underlying self-infliction of pain during thinking for ...
Participants clicked pens with uncertain shock administration most ... that pressing the button(s) was allowed during the waiting period, ...
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