本文介绍了运行“google-chrome"在 WSL Ubuntu 上作为 --headless --no 沙箱给出了多个错误 - 如何在 WSL 中使用 headless 截取屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行的是 Windows 10,并且一直在 Windows Linux 子系统下使用 Ubuntu Linux 发行版.

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

我希望能够使用 Chrome.exe 或 google-chrome 无头运行并截取屏幕截图、生成 pdf 等...作为库调用的一部分,但看不到这样做(例如使用 jupyter_to_medium 库在后台启动 chrome 以截取屏幕截图).

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).

我尝试了多种方法来独立于我正在使用的库或程序使用 google-chrome 调试它.

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

这是我尝试过的:

  1. 可以通过 Ubuntu 终端启动 Chrome(Windows 可执行文件),并将其重定向到 Windows 可执行文件:

  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

当我这样做时,我的 Windows Chrome 浏览器中会打开一个新标签页,所以这里没有问题.

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

当我尝试在 ubuntu 终端中使用 google-chrome headless 时,我得到多个问题,例如

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

2a) 试图获取屏幕截图 - FAILs 显示 网络服务崩溃,重新启动服务 无限循环 - 必须按 CTRL^C 来停止它

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) 尝试使用 不同参数 --no-sandbox --disable-setuid-sandbox 获取屏幕截图,这次得到不同的错误.

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: ```

  • 尝试使用相同的参数运行 Windows 可执行文件 Chrome.exe,似乎可以运行但未截取屏幕截图(我的目录中没有新文件)

  • 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)

    尝试在 WSL 中运行 google-chrome 没有 提升的权限,我得到一个不同的错误:

    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/无法移动到新命名空间:支持 PID 命名空间,支持网络命名空间,但失败:errno =Permission denied 生成 minidump 失败.非法指令(core dumped)

    任何帮助或指导将不胜感激.我的另一个选择是在带有本机 Linux UI 和终端的 Windows 10 上运行虚拟机,这可能会奏效.

    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.

    但是有没有办法在 WSL 中进行所有设置?

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

    谢谢.

    推荐答案

    试试这个(在 wsl2 中测试)

    Try this (tested in wsl2)

    在您的 wsl2 ubuntu 控制台中输入以下命令:

    In your wsl2 ubuntu console enter the following commands:

    #install packages
    sudo apt-get install -y curl unzip xvfb libxi6 libgconf-2-4
    #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/
    

    这篇关于运行“google-chrome"在 WSL Ubuntu 上作为 --headless --no 沙箱给出了多个错误 - 如何在 WSL 中使用 headless 截取屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-07 07:03