Skip to content

UnhandledPromiseRejectionWarning on Navigation Timeout Exceeded #2482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hkhan-lumatax opened this issue Apr 30, 2018 · 9 comments
Closed

UnhandledPromiseRejectionWarning on Navigation Timeout Exceeded #2482

hkhan-lumatax opened this issue Apr 30, 2018 · 9 comments
Labels
bug chromium Issues with Puppeteer-Chromium unconfirmed

Comments

@hkhan-lumatax
Copy link

hkhan-lumatax commented Apr 30, 2018

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?

@yusufilkeroguz
Copy link

yusufilkeroguz commented May 1, 2018

same problem here.

node-v: 9.7.1

goPage: async function (url) {
        let page = await this.page;

        await page.goto(url);
        await page.setViewport({width: 1366, height: 768});

        try {
            const waitNavigationPromise = page.waitForNavigation({timeout: 10000, waitUntil: "load"});

            await waitNavigationPromise;

            return await page;
        }
        catch(e) {
            this.catchError(e, page);

            return false;
        }
    },
Error: Navigation Timeout Exceeded: 10000ms exceeded
    at Promise.then (/var/www/crawler/node_modules/puppeteer/lib/NavigatorWatcher.js:73:21)
    at <anonymous>

@aslushnikov
Copy link
Contributor

@hkhan-lumatax can you please provide a reproducible example? It should be a script that I'll be able to run locally to see the issue.

We won't be able to help otherwise.

@aetheryx
Copy link

@aslushnikov I seem to have ran into the same issue. Here's a reproducible example:

const puppeteer = require('puppeteer');

const getData = async () => {
  const browser = await puppeteer.launch({
    executablePath: '/usr/bin/chromium',
    headless: false
  });

  const page = await browser.newPage();
  page.goto('https://discordbots.org');

  await page.waitFor('.bot-list-section')

  const data = await page.$$eval('.bot-card', divs => Array.from(divs).map(bot => ({
    id: bot.querySelector('.info a').href.split('/').pop(),
    name: bot.querySelector('.bot-name').innerHTML,
    status: bot.querySelector('.status').innerHTML
  })))

  browser.close();
  return data;
};

getData()
  .then(data => {
    console.log(data.length);
  });

The browser opens, the result gets logged and the browser closes. The process idles for 30 seconds. The error gets logged, and then the process exits.

The error does not occur if you await the page.goto(...) call. It should also be noted that the issue only occurs with websites that "load slowly" (referring to the spinner at the top of the tab), possibly because browser.close() is called before the promise from page.goto(...) resolves?

My environment information:

  • Puppeteer version: 1.4.0
  • Platform / OS version: Arch Linux 4.14.15-1
  • Node.js version: 10.1.0

@aslushnikov
Copy link
Contributor

@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'});

@aslushnikov aslushnikov added the chromium Issues with Puppeteer-Chromium label Dec 6, 2018
@motsmanish
Copy link

'load' worked for me:

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

@nhhockeyplayer
Copy link

im seeing neither works
domcontentloaded relieves the exception but produces no query data
load produces query data and an exception
there is a race condition between the latter when data sometimes queries

@loomp
Copy link

loomp commented Apr 21, 2020

same problem here.

node-v: 9.7.1

goPage: async function (url) {
        let page = await this.page;

        await page.goto(url);
        await page.setViewport({width: 1366, height: 768});

        try {
            const waitNavigationPromise = page.waitForNavigation({timeout: 10000, waitUntil: "load"});

            await waitNavigationPromise;

            return await page;
        }
        catch(e) {
            this.catchError(e, page);

            return false;
        }
    },
Error: Navigation Timeout Exceeded: 10000ms exceeded
    at Promise.then (/var/www/crawler/node_modules/puppeteer/lib/NavigatorWatcher.js:73:21)
    at <anonymous>

I believe you were doing it the wrong way.

You shall define waiter promise at first, call the URL change and then await waiter promise to complete.

const waiter = page.waitForNavigation({
  waitUntil: 'networkidle0',
});

await page.goto(url);

await waiter;

Of course, you can add waitUntil option into goto call directly as well.

@stale
Copy link

stale bot commented Jun 26, 2022

We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days.

@stale stale bot added the unconfirmed label Jun 26, 2022
@stale
Copy link

stale bot commented Jul 26, 2022

We are closing this issue. If the issue still persists in the latest version of Puppeteer, please reopen the issue and update the description. We will try our best to accomodate it!

@stale stale bot closed this as completed Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug chromium Issues with Puppeteer-Chromium unconfirmed
Projects
None yet
Development

No branches or pull requests

8 participants
@aslushnikov @motsmanish @yusufilkeroguz @nhhockeyplayer @aetheryx @hkhan-lumatax @loomp and others