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.

waitForNavigation doesn't work after evaluate fetch() or XMLHttpRequest()

See original GitHub issue

Puppeteer version: 0.13.0 Platform / OS version: Win10x64 / Chromium 64.0.3264.0

const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch({headless:false,userDataDir:'test-profile-dir'});
const page = await browser.newPage();
await page.setRequestInterception(true);
await page.on('request', request => {
    request.continue();
});
await page.goto("https://www.npmjs.com/",{waitUntil: ['networkidle0','load','domcontentloaded'],timeout:10000}).catch(error=>console.log(error));
await page.evaluate(async () => {fetch("https://www.npmjs.com/features").then( response => response.text() ).then( html => document.body.innerHTML=html )}).catch(error=>console.log(error));
await page.waitForNavigation({waitUntil: ['networkidle0','load','domcontentloaded'],timeout:10000}).catch(error=>console.log(error));
await page.goto("https://www.npmjs.com/pricing",{waitUntil: ['networkidle0','load','domcontentloaded'],timeout:10000}).catch(error=>console.log(error));
await browser.close();
})();

it returns the result as below

Error: Navigation Timeout Exceeded: 10000ms exceeded

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
remorsescommented, Mar 17, 2018

I had the same iussue and resolved using a recursive function that reset itself every request, and after a small time of idle network ( time parameter ) resolves.

const waitForLoad = (page, time) => new Promise((resolve) => {
  page.on('rquest', (req) => {
    waitForLoad(page, time)
  })
  page.on('requestfinished', (req) => {
    setTimeout(() => resolve("timeOut"), time)
  })
})

use like this

await page.click("button")
await waitForLoad(page, 800)
1reaction
erlichmencommented, May 15, 2018

@remorses use .once() instead of .on()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer: page.evaluate not working after waitForNavigation ...
This resolves when the page navigates to a new URL or reloads. It never happens, so your code does not continue. You might...
Read more >
Puppeteer documentation - DevDocs
Puppeteer 7.1.0 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
Read more >
Dealing with Asynchrony when Writing End-To-End Tests with ...
In this article we present an overview on how to deal with asynchrony ... first getting the message using the evaluate() Puppeteer function....
Read more >
Scraping dynamic content - Apify Documentation
Wait for dynamically loaded content when web scraping. See code examples and a detailed breakdown for setting timeouts and custom wait functions.
Read more >
node_modules/puppeteer/lib/types.d.ts - devtools ... - Google Git
This won't share cookies/cache with other. * browser contexts. *. * @example. * ```js. * (async () => {. * const browser =...
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