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.

page.goto always times out in Windows Subsystem for Linux (WSL)

See original GitHub issue

Steps to reproduce

  1. mkdir puppeteer_test
  2. cd puppeteer_test
  3. npm init -y
  4. npm i puppeteer
  5. touch index.js
  6. put the following into index.js:
const puppeteer = require('puppeteer');

main = () => {
    let browser;
    let page;
    return Promise.resolve()
        .then(() => {
            console.log('Launching browser');
            return puppeteer.launch({ args: ['--no-sandbox'] });
        })
        .then((result) => {
            browser = result;
        })
        .then(() => {
            return browser.newPage();
        })
        .then((result) => {
            page = result;
        })
        .then(() => {
            console.log('Navigating');
            return page.goto('https://github.com/puppeteer/puppeteer');
        })
        .then(() => {
            console.log('Taking screenshot');
            return page.screenshot({ path: 'test.png' });
        })
        .then(() => {
            if (browser) {
                console.log('Closing browser');
                return browser.close().then(() => {
                    console.log('Browser closed');
                });
            } else {
                return Promise.resolve();
            }
        })
        .catch((error) => {
            return Promise.reject(error);
        });
};

main()
    .then(() => {
        console.log('Completed successfully');
    })
    .catch((error) => {
        console.error(error);
    })
    .finally(() => {
        console.log('Done');
    });
  1. node index.js

Environment

  • Puppeteer version: ^5.2.1
  • Platform / OS version: Windows Subsystem for Linux (WSL)
  • Node.js version: v12.18.0

What is the expected result?

There should not be errors, and a screenshot should be taken.

What happens instead?

I get the following output:

Launching browser
Navigating
TimeoutError: Navigation timeout of 30000 ms exceeded
    at /c/Users/*******/home/puppeteer_test/node_modules/puppeteer/lib/cjs/puppeteer/common/LifecycleWatcher.js:106:111
Done

and then the program hangs. This happens no matter what URL I enter.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

4reactions
nullromocommented, Sep 8, 2020

Based on this comment I found that this worked for me:

return puppeteer.launch({
    args: [
        '--no-sandbox',
        '--no-zygote',
        '--single-process',
    ],
});

Further, I had to add the --disable-gpu flag to run in headless: false mode.

1reaction
pkerschbaumcommented, Mar 13, 2022

In case this helps someone, I had random timeouts using Puppeteer or Playwright on WSL 2.
It was actually a problem of WSL 2 itself, this workaround solved the issues: https://github.com/microsoft/WSL/issues/7254#issuecomment-905767204

Read more comments on GitHub >

github_iconTop Results From Across the Web

WSL Ubuntu bash: The operation timed out because a ...
... solution solved this problem: A full reboot of Windows10, by opening Windows > Start Menu > Power > Restart while holding the...
Read more >
c++ - Intermittent, random 'file not found' errors under Windows ...
I'm getting intermitting 'fatal error: ... file not found' errors building C++ application using either gcc 4.8 or clang 3.8 under Ubuntu 16.04....
Read more >
Troubleshooting Windows Subsystem for Linux | Microsoft Learn
Open Control Panel -> Programs and Features -> Turn Windows Feature on or off -> Check Windows Subsystem for Linux or using the...
Read more >
Developing in WSL - Visual Studio Code
The Visual Studio Code WSL extension lets you use the Windows Subsystem for Linux (WSL) as your full-time development environment right from VS...
Read more >
Setting Up Docker for Windows and WSL to Work Flawlessly
With a couple of tweaks the WSL (Windows Subsystem for Linux, ... get an error the next time you start your WSL terminal...
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