page.goto always times out in Windows Subsystem for Linux (WSL)
See original GitHub issueSteps to reproduce
mkdir puppeteer_testcd puppeteer_testnpm init -ynpm i puppeteertouch index.js- 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');
});
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:
- Created 3 years ago
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Based on this comment I found that this worked for me:
Further, I had to add the
--disable-gpuflag to run inheadless: falsemode.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