2

Is there a straightforward way to run Puppeteer on wsl2? I've tried many solutions across the web and read tons of forums looking for answers. So far no success and I've found running Puppeteer very easy in windows but extremely difficult in wsl2.

I've tried downloading chrome and chromium, and specifying the executablePath with no luck.

I know that it works on my windows system, but cannot seem to get Puppeteer to run in wsl2.

I am currently stuck on this error:

Timeout Error: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r1022525 is guaranteed to work.

When looking into node_modules I can see that version 1022525 is in use. I can't understand what Puppeteer's problem is nor how to fix it.

Anyone have any ideas?

Robert
  • 176
  • 1
  • 12
  • Potentially related WSL2 issues [#1837](https://github.com/puppeteer/puppeteer/issues/1837), [Running Puppeteer on WSL2 controlling the Chrome on Windows](https://stackoverflow.com/questions/67703601/running-puppeteer-on-wsl2-controlling-the-chrome-on-windows), [Failed to launch the browser process!/usr/bin/chromium-browser' requires the chromium snap to be installed](https://stackoverflow.com/questions/71835297/failed-to-launch-the-browser-process-usr-bin-chromium-browser-requires-the-chr), [Troubles to show the browser using puppeteer from WSL2](https://stackoverflow.com/questions/67314985/) – ggorlen Aug 31 '22 at 20:00
  • Are you trying to run browser executable on Windows or Linux/WSL2? And are you running Windows 10 or 11? – NotTheDr01ds Sep 01 '22 at 01:12
  • @NotTheDr01ds I'm running the browser on WSL2, or at least trying to (I'm trying to use XcSrv on WSL2). And I'm running windows 10. I've also tried using Docker to create an image and run Puppeteer from within the container. Still no luck. – Robert Sep 07 '22 at 17:32

1 Answers1

2

As I do not see exactly what are you trying to do , in the moment I can think that this error accused because of your windows defender firewall, which do not allow access of your X-server.

anyway for me I use Puppeteer on wsl2 as following:

  1. I need to install VcXsrc as X-server to display what is going on in the Linux side of the computer. https://sourceforge.net/projects/vcxsrv notes: you need to allow “Public networks” when the Windows firewall pops up.

  2. You need now to set a DISPLAY environment variable has to be set,becuase wsl has its own IP address, we need to connect to our X-server app using this IP so to do this follow the next steps.

  3. In your .bashrc (or .zshrc if you are using ZSH) add this line exactly to the end: export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0

  4. now executes the content of your bash use source ~/.bashrc (or source ~/.zshrc if you are using ZSH)

  5. to be sure that your DISPLAY environment variable has set correctly , try this command (echo $DISPLAY) the result should be something like this : # 172.16.210.1:0.0 it will be your wsl IP address.

  6. now Open the VcXsrv program in Windows (called XLaunch), allow this options step after step “Multiple windows” and “Start no client”. and in the end tick the option of disable access control Be sure to disable access control.

  7. as last check go to windows defender firewall and be sure that you enable all network connection for VcXSrv. now you are ready to go, let suppose I am using puppeteer to test inside jest file like the follwoing :

    const puppeteer = require('puppeteer'); test('should create an element...etc', async () => { const browser = await puppeteer.launch({ headless: false, args: ['--window-size=1920,1080'] }); const page = await browser.newPage(); await page.goto( 'www.google.com' ); });

start the last code using (jest nameofyourtestfile) and your puppeteer will work as you like, Chromium will open in your windows ...enjoy...if there is any details which is not clear may you ask again. I hope that I helped

Barry
  • 33
  • 5
  • Sorry for taking so long to respond. I had seen this sort of solution in other articles online but it didn't work as I expected. Puppeteer will run headless but I have still never found a way to run it headless = false ("headful"?). – Robert Mar 16 '23 at 00:33