waitForNavigation doesn't work after clicking a link
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: 0.13.0
- Platform / OS version: Win10x64 / Chromium 64.0.3270.0 r516713
What steps will reproduce the problem?
const puppeteer = require('puppeteer');
(async () => {
try {
const browser = await puppeteer.launch({
headless : false,
executablePath : 'D:/path/to/chromium/chrome.exe',
userDataDir : 'D:/path/to/userdir',
args : ['about:blank']
});
const pages = await browser.pages();
const page = pages[0];
page.on('load', () => console.log('Loaded: ' + page.url()));
// goto: page1.html
await page.goto('https://leo020588.bitbucket.io/page1.html', {waitUntil: 'load'});
// workaround-fix
/*await page.evaluate(() => {
let link = document.querySelector('a');
link.addEventListener('click', (event) => {
event.preventDefault();
event.stopPropagation();
window.location = link.href;
});
});*/
// click: link (page2.html)
await page.click('a');
//
await page.waitForNavigation({waitUntil: 'load'});
console.log('page2.html has arrived ... the wait is over');
//
await browser.close();
} catch (e) {
console.log(e);
}
})();
What is the expected result?
page2.html has arrived ... the wait is over
What happens instead?
Error: Navigation Timeout Exceeded: 30000ms exceeded
Note
If I uncomment the workaround-fix
works as espected.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:12
- Comments:31 (7 by maintainers)
Top 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 >Page.waitForNavigation() method - Puppeteer
Waits for the page to navigate to a new URL or to reload. It is useful when you run code that will indirectly...
Read more >Puppeteer documentation - DevDocs
Puppeteer 7.1.0 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
Read more >Navigations - Playwright 中文文档 - Bootstrap
The navigation intent may be canceled, for example, on hitting an unresolved DNS ... Navigating to a URL auto-waits for the page to...
Read more >Navigating & waiting - Checkly
waitForXpath() function is you are using XPath selectors instead of CSS selectors. page.waitForNavigation(). In your scripts you can click on a link that ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@ebidel Sorry if this is not the place to discuss standard-javascript implementation/understanding. What suggested @vsemozhetbyt works for me. But I still think your suggestion has the same behavior as my code, I would like to clarify if am I wrong for not to confuse other readers before I close the issue.
OPTION-1 (@leo020588) - my original code doesn’t work as expected (Error: Navigation Timeout)
OPTION-2 (@vsemozhetbyt) - works as expected (“The wait is over 2”)
OPTION-3 (@ebidel) - doesn’t work as expected (Error: Navigation Timeout)
Edit: I like @aslushnikov’s approach better, it makes more sense:
@leo020588 another way to think of
waitForNavigation
is that it waits for the navigation to start and complete.In your case, the
await page.click('a')
returns control to the script too late - the navigation has already started.The handy way to do this is: