17

I'm running Windows 10 and I have been using an Ubuntu Linux distro under the Windows Linux Subsystem.

I want to be able to use Chrome.exe or google-chrome to run headless and take screenshots, generate pdfs etc... as part of library calls, but can't see to do that (e.g. to use jupyter_to_medium library launches chrome in the background to take screenshot).

I have tried multiple things to debug it with google-chrome independently of the library or programme I'm using.

Here's what I've tried:

  1. I can launch Chrome (Windows executable) via the Ubuntu terminal, having redirected it to the Windows executable:

    /mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe
    

    When I do that, a new tab opens in my Windows Chrome browser so no issues here.

  2. When I try to use google-chrome headless in ubuntu terminal I get MULTIPLE ISSUES e.g.

    2a) Trying to get a screenshot - FAILs showing Network service crashed, restarting service endless loop - had to CTRL^C to stop it

     (base) etzimopoulos@DESKTOP-HI9P6E4:~$ google-chrome --headless --disable-gpu --screenshot https://www.chromestatus.com/
    [0626/055458.471044:ERROR:udev_watcher.cc(61)] Failed to enable receiving udev events.
    [0626/055458.612113:ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service.
    [0626/055458.696014:ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service.
    ...
    

    2b) Trying to get a screenshot using a different parameters --no-sandbox --disable-setuid-sandbox , getting different error this time.

    $ sudo google-chrome --no-sandbox --disable-setuid-sandbox --headless --screenshot https://www.chromestatus.com/
    [0626/061854.348849:ERROR:udev_watcher.cc(61)] Failed to enable receiving udev events.
    [0626/061855.311675:ERROR:platform_shared_memory_region_posix.cc(46)] Descriptor access mode (0) differs from expected (2)
    [0626/061855.312483:WARNING:crash_handler_host_linux.cc(366)] Could not translate tid - assuming crashing thread is thread group leader; syscall_supported=0
    [0626/061855.474617:WARNING:crash_handler_host_linux.cc(366)] Could not translate tid - assuming crashing thread is thread group leader; syscall_supported=0
    --2020-06-26 06:18:55--  https://clients2.google.com/cr/report
    Resolving clients2.google.com (clients2.google.com)... 216.58.210.46, 2a00:1450:4009:800::200e
    Connecting to clients2.google.com (clients2.google.com)|216.58.210.46|:443... connected.
    HTTP request sent, awaiting response... [0626/061855.655013:ERROR:headless_shell.cc(399)] Abnormal renderer termination.
    429 Too Many Requests
    2020-06-26 06:18:55 ERROR 429: Too Many Requests.
    
    
    Unexpected crash report id length
    Failed to get crash dump id.
    Report Id: ```
    
    
  3. Trying to run the Windows executable Chrome.exe with same parameters, seems to run but not screenshot is being taken (no new files in my directory)

  4. Trying to run google-chrome without elevated privilages in WSL I get a different error:

    google-chrome --headless --disable-gpu --screenshot https://www.chromestatus.com/ Failed to move to new namespace: PID namespaces supported, Network namespace supported, but failed: errno = Permission denied Failed to generate minidump.Illegal instruction (core dumped)

Any help or direction would be hugely appreciated. My other option would be to run a VM on windows 10 with native Linux UI and terminal, which would probably work.

But is there a way to have it all setup in WSL?

Thank you.

Angelo
  • 341
  • 1
  • 2
  • 11

1 Answers1

31

Try this (tested in wsl2)

In your wsl2 ubuntu console enter the following commands:

#install packages
sudo apt-get install -y curl unzip xvfb libxi6 libgconf-2-4 fonts-liberation
#get latest chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

#install it
sudo apt install ./google-chrome-stable_current_amd64.deb

#test a screenshot
google-chrome --headless --disable-gpu --screenshot https://www.chromestatus.com/
krsche_
  • 178
  • 1
  • 8
Jinxmcg
  • 1,830
  • 1
  • 21
  • 24
  • 5
    Worked perfectly! – Marshal Feb 17 '21 at 04:18
  • It is not working to me: WSL2 Ubuntu: 1124/141516.139879:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2) [1124/141516.139982:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2) [1] 6863 trace trap google-chrome – Alejandro Sanz Díaz Nov 24 '21 at 13:20
  • 1
    @AlejandroSanzDíaz this seems like you cannot start google chrome, and there is a bug open for google chrome to fix it https://bugs.chromium.org/p/chromium/issues/detail?id=1228625 my suggestion is to try a known working version of chrome instead of stable_current some users reported google-chrome-stable=93.0.4577.82-1 is working fine so try this version http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_93.0.4577.82-1_amd64.deb – Jinxmcg Nov 25 '21 at 15:16
  • Thank you @Jinxmcg. Looks like, as in the bug comments is reported, using --disable-gpu solves the issue. – Alejandro Sanz Díaz Nov 26 '21 at 15:01
  • In the code I posted as initial answer the last line recommended using --headless and --disable-gpu as parameters to google chrome – Jinxmcg Nov 27 '21 at 16:19
  • see this answer for ways to install specific versions: https://unix.stackexchange.com/a/590412/402487 – krsche_ Feb 02 '22 at 00:12
  • 1
    In addition, I would suggest u to use the `no-sandbox` argument as well as use the suitable version as mentioned in https://stackoverflow.com/questions/62588767/running-google-chrome-on-wsl-ubuntu-as-headless-no-sandbox-gives-multiple#comment123941166_65992939 and download the chromedriver accordingly e.g. download older version https://chromedriver.storage.googleapis.com/index.html?path=93.0.4577.82/ if u plan to use it with chromedriver – abmap Mar 04 '22 at 03:08