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.

How to silence 'Navigation failed because browser has disconnected'

See original GitHub issue

How to I silence this error (node:12171) UnhandledPromiseRejectionWarning: Error: Navigation failed because browser has disconnected!

page.goto('https://example.com/')
await page.waitFor('body')
const body = await page.evaluate(() => document.querySelector('body').textContent)
console.log(body)

await this.page.close()
await browser.close()

I can get body element successfully but because the browser closes before the page.goto has finished I get disconnected error which I want to silence. (not sure if this specific example works, this is pseudo code I haven’t tested)

Issue Analytics

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

github_iconTop GitHub Comments

13reactions
ghostcommented, Apr 11, 2019

I think this might have fixed my problem

await Promise.race([
  this.page.goto('https://example.com/'),
  this.page.waitFor('body')
])
8reactions
ghostcommented, Apr 13, 2019

I’m actually still getting a problem that I don’t get how to solve. It seems that no matter how many try catch I put it doesn’t catch the error and stops my program. It’s hard to debug cause it only happens every few hours and not sure what causes it but it only happens when I use page.waitFor

try {
  try {
    try {
      try {
        const timeout = 180 * 1000
        await Promise.race([
          page.goto('https://example.com/', {timeout}),
          page.waitFor('body', {timeout})
        ])
      }
      catch (e) {}
    }
    catch (e) {}
  }
  catch (e) {}
}
catch (e) {}
(node:75313) UnhandledPromiseRejectionWarning: TimeoutError: waiting for target failed: timeout 30000ms exceeded
    at Function.waitWithTimeout (/node_modules/puppeteer/lib/helper.js:214:26)
    at Browser.waitForTarget (/node_modules/puppeteer/lib/Browser.js:214:27)
    at Browser.<anonymous> (/node_modules/puppeteer/lib/helper.js:111:23)
    at Launcher.launch (/node_modules/puppeteer/lib/Launcher.js:178:21)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:75313) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:75313) [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.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Navigation failed because browser has disconnected ...
The Navigation failed because browser has disconnected error usually means that the node scripts that launched Puppeteer ends without ...
Read more >
error: navigation failed because browser has disconnected!
The Navigation failed because browser has disconnected error usually means that the node scripts that launched Puppeteer ends without waiting for the ...
Read more >
Navigation failed because browser has disconnected!
[1] Navigation failed because browser has disconnected! (An internal WebSocket error occurred. Please see the innerException, if present, for ...
Read more >
Node.js – Why is puppeteer reporting ... - iTecNote
The Navigation failed because browser has disconnected error usually means that the node scripts that launched Puppeteer ends without waiting for the Puppeteer ......
Read more >
Navigation failed because browser has disconnected
Starting March 15th, our previously passing tests started failing with the message: “Navigation failed because browser has disconnected!
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