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.

UnhandledPromiseRejectionWarning on Navigation Timeout Exceeded

See original GitHub issue

Steps to reproduce

Environment:

  • Puppeteer version: 1.3.0
  • Platform / OS version: macOS 10.13.1
  • Node.js version: 8.9.4

Steps

Below is the code producing this problem:

try {
  ...
  await page.waitForNavigation({waitUntil: 'networkidle2'})
  ...
} catch (err) {
  // Throw an error.
  throwError(err, page, browser, res)
}

throwError = (async (err, page, browser, res) => {
    // Log the error.
    console.log(err)

    // Close the browser.
    await page.close()
    await browser.close()

    // Return an error response message.
    res.json({code: 'ERROR', message: 'An unexpected error has occurred.'})
})

When a request times out, I get the following error:

Error: Navigation Timeout Exceeded: 30000ms exceeded
    at Promise.then (node_modules/puppeteer/lib/NavigatorWatcher.js:73:21)
    at <anonymous>
(node:72563) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Protocol error (Runtime.callFunctionOn): Target closed.
(node:72563) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

What is the expected result?

The page and browser should get closed without throwing an exception/error.

What happens instead?

Error: Protocol error (Runtime.callFunctionOn): Target closed. is displayed instead of the page and browser getting closed gracefully. Timeout Exceeded error is understandable and is correct.

I want to understand why Error: Protocol error (Runtime.callFunctionOn): Target closed. is being thrown and how we can avoid it?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

60reactions
aslushnikovcommented, May 17, 2018

@Aetheryx Thanks, I see what’s going on here. That’s somewhat related to #1454; as a workaround, I’d recommend navigating until domcontentloaded event:

await page.goto('https://discordbots.org', {waitUntil: 'domcontentloaded'});
5reactions
motsmanishcommented, May 1, 2019

‘load’ worked for me:

await page.goto('http://example.com', {waitUntil: 'load'});

Read more comments on GitHub >

github_iconTop Results From Across the Web

Puppeteer throws "UnhandledPromiseRejectionWarning ...
I changed "example.com" because works fine and trying with other sites, but with "github.com" script returns an timeout exception in the await ...
Read more >
How to solve Puppeteer TimeoutError: Navigation timeout of ...
To solve this problem, you will have 2 options, either to increase this timeout in the configuration or remove it at all. Personally,...
Read more >
Fix: navigation timeout of 30000 ms exceeded in puppeteer?
In this video, I am going to show you how we can fix navigation timeout of 30000 ms exceeded in puppeteer.You will generally...
Read more >
Fix: navigation timeout of 30000 ms exceeded in puppeteer?
r/node - Why is the function that uses stream taking longer?
Read more >
navigation timeout of 30000 ms exceeded, puppeteer console
The main type of error that's encountered is a timeout. The issue is that there's no documented way to distinguish the type of...
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