puppeteer: Execution hangs when browser window goes to background

Steps to reproduce

  • Puppeteer version: 1.6.2
  • Chromium: 69.0.3494.0 (Developer Build)
  • Platform / OS version: macos sierra
  • Node.js version: v10.8.0

What steps will reproduce the problem?

  • Run the following script. It opens google and submits form, repeating 10 times.
const puppeteer = require('puppeteer')

main()

async function main() {
  const browser = await puppeteer.launch({
    args: [
      // all related chromium flags I could find
      '--disable-background-timer-throttling',
      '--disable-renderer-backgrounding',
      '--override-plugin-power-saver-for-testing=never',
      '--disable-extensions-http-throttling',
    ],
    headless: false
  })
  const timeout = 5000
  const page = await browser.newPage()
  for (let i = 0; i < 10; i++) {
    console.log(`navigating ${i}`)
    await page.goto('https://google.com', {timeout})
    const input = await page.$('input[type="text"]')
    await input.type('test')
    await Promise.all([
      page.waitForNavigation({timeout}),
      page.evaluate(() => document.querySelector('input[type="submit"]').click())
    ])
  }
}
  • Switch to any other fullscreen-size window, so puppeteer browser window is not visible.

What is the expected result?

Scripts proceeds till end without errors.

What happens instead?

UnhandledPromiseRejectionWarning: Error: Navigation Timeout Exceeded: 5000ms exceeded

Some explorations

This happens only when puppeteer window is not visible at all. When even couple of pixels of this window are visible everything works fine.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 24 (3 by maintainers)

Most upvoted comments

[Solution]:

Add the following values to the array you assign to the args property in the options object. Now, you should be able to run Puppeteer while your window is in the foreground, background, or minimized.

const chromeArgs = [
  '--disable-background-timer-throttling',
  '--disable-backgrounding-occluded-windows',
  '--disable-renderer-backgrounding'
];

Solution and explanation available in an article written by Rohit Kumar, @rkr090 at Big Binary:

Debugging failing tests in puppeteer because of background tab

Can confirm the issue on Windows 10 with Chrome 72.0.3626.81. Mine freezes when attempt to click on element and chrome windows is in the background. Is there are any workaround?

I tried to play with chrome://flags image no effect

The same issue on Windows and minimized Chrome window. Timeout extended to 20sec. First navigation completes and then things just hang until the window is shown.

I haven’t had time to test this yet, but I’m fairly certain #3148 is a duplicate of this issue

script (code snippet) you gave ran successfully when I added the timeout = 30000 but I realized one more thing that if your internet connection is too low, it will throw error even after timeout = 30000

Your timeout isn’t sufficient Ex. Increase it to some large value like const timeout = 30000 OR just remove timeout and it will work perfect without any errors

UnhandledPromiseRejectionWarning: Error: Navigation Timeout Exceeded: 5000ms exceeded => means naviagtion isn’t completing before 5000ms