如何在无头 Ubuntu 服务器上运行 Chrome headful?

问题描述 投票:0回答:1

所以我有这个 Node.js 应用程序,它使用 Puppeteer(例如 Selenium 的替代品),它是一个浏览器机器人/Web 驱动程序。对于我的特定用例,我需要运行 Chrome headful,但我就是无法让它工作。

我几乎没有任何 Linux 知识。我确实有不错的终端知识,因为我使用的是 MacOS,但也仅此而已。

我想要无头 Ubuntu 服务器的原因是为了节省 RAM,因为我真的不需要 GUI 来做任何事情。是否有可能实现我想要实现的目标?

到目前为止,我已经尝试使用 `Xvfb` 但 Chrome 只给了我一堆错误:

root@x:~# Xvfb -ac :99 -screen 0 1280x1024x16 > /dev/null 2>&1 &
[1] 3204
root@x:~# DISPLAY=:99.0 chromium --no-sandbox
[3207:3284:0503/123414.921007:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.DBus.ListActivatableNames: object_path= /org/freedesktop/DBus: org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.5" (uid=0 pid=3207 comm="/snap/chromium/2842/usr/lib/chromium-browser/chrom" label="snap.chromium.chromium (enforce)") interface="org.freedesktop.DBus" member="ListActivatableNames" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)
[3207:3207:0503/123415.185094:ERROR:chrome_browser_cloud_management_controller.cc(161)] Cloud management controller initialization aborted as CBCM is not enabled. Please use the `--enable-chrome-browser-cloud-management` command line flag to enable it if you are not using the official Google Chrome build.
[3207:3284:0503/123415.446231:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.DBus.ListActivatableNames: object_path= /org/freedesktop/DBus: org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.7" (uid=0 pid=3207 comm="/snap/chromium/2842/usr/lib/chromium-browser/chrom" label="snap.chromium.chromium (enforce)") interface="org.freedesktop.DBus" member="ListActivatableNames" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)
[3306:3306:0503/123415.812393:ERROR:gl_surface_egl.cc(302)] No suitable EGL configs found.
[3306:3306:0503/123415.814730:ERROR:gl_context_egl.cc(160)] eglGetConfigAttrib failed with error EGL_BAD_CONFIG
libva error: /snap/chromium/2842/gnome-platform/usr/lib/x86_64-linux-gnu/dri/virtio_gpu_drv_video.so init failed
[3306:3306:0503/123415.889614:ERROR:gl_surface_egl.cc(302)] No suitable EGL configs found.
[3306:3306:0503/123415.889924:ERROR:gl_surface_egl.cc(1040)] eglCreatePbufferSurface failed with error EGL_BAD_CONFIG
[3306:3306:0503/123415.893292:ERROR:gpu_info_collector.cc(86)] gl::GLContext::CreateOffscreenGLSurface failed
[3306:3306:0503/123415.893950:ERROR:gpu_info_collector.cc(582)] Could not create surface for info collection.
[3306:3306:0503/123415.894861:ERROR:gpu_init.cc(103)] CollectGraphicsInfo failed.
[3306:3306:0503/123415.919347:ERROR:viz_main_impl.cc(198)] Exiting GPU process due to errors during initialization
(chrome:3207): IBUS-WARNING **: 12:34:16.415: Failed to mkdir /root/snap/chromium/2842/.config/ibus/bus: Not a directory
[3207:3358:0503/123416.661211:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[3207:3358:0503/123416.661747:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.UPower.GetDisplayDevice: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[3207:3358:0503/123416.662276:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.UPower.EnumerateDevices: object_path= /org/freedesktop/UPower: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.UPower was not provided by any .service files
[3356:3356:0503/123417.103803:ERROR:gl_surface_egl.cc(302)] No suitable EGL configs found.
[3356:3356:0503/123417.104363:ERROR:gl_context_egl.cc(160)] eglGetConfigAttrib failed with error EGL_BAD_CONFIG
libva error: /snap/chromium/2842/gnome-platform/usr/lib/x86_64-linux-gnu/dri/virtio_gpu_drv_video.so init failed
[3356:3356:0503/123417.110956:ERROR:gl_surface_egl.cc(302)] No suitable EGL configs found.
[3356:3356:0503/123417.111222:ERROR:gl_surface_egl.cc(1040)] eglCreatePbufferSurface failed with error EGL_BAD_CONFIG
[3356:3356:0503/123417.111440:ERROR:gpu_info_collector.cc(86)] gl::GLContext::CreateOffscreenGLSurface failed
[3356:3356:0503/123417.111605:ERROR:gpu_info_collector.cc(582)] Could not create surface for info collection.
[3356:3356:0503/123417.111767:ERROR:gpu_init.cc(103)] CollectGraphicsInfo failed.
[3356:3356:0503/123417.138033:ERROR:viz_main_impl.cc(198)] Exiting GPU process due to errors during initialization
libva error: /snap/chromium/2842/gnome-platform/usr/lib/x86_64-linux-gnu/dri/virtio_gpu_drv_video.so init failed
[3339:3353:0503/123417.516431:ERROR:command_buffer_proxy_impl.cc(131)] ContextResult::kTransientFailure: Failed to send GpuControl.CreateCommandBuffer.

我不知道发生了什么,也不知道如何开始修复这些问题😅

希望有人能帮助我,我将不胜感激!

linux google-chrome ubuntu server puppeteer
1个回答
0
投票

解决了这个问题。基本上是 https://github.com/mujo-code/puppeteer-headful/blob/master/Dockerfile 和一些试验和错误的组合,我把它启动并运行了。

快速概览:

  • 通过安装
    google-chrome-stable
    来安装正确的依赖项(参见链接)
  • 使用
    execPath
  • 将新的 chrome 作为可执行文件传递给 puppeteer
  • 使用
    Xvfb
    托管显示服务器
  • 使用
    env.DISPLAY
  • 将端口和屏幕传递给 puppeteer
  • 添加标志参数:
    ["--no-sandbox", "--disable-setuid-sandbox", "--disable-gpu"]

没有 GUI,没有 WM,没有合成器设置或任何东西。直接在 Ubuntu 服务器上运行。

© www.soinside.com 2019 - 2024. All rights reserved.