如何在无头模式下启动 Chrome 浏览器?显示“:99”上缺少扩展“RANDR”

zab*_*mba 7 google-chrome chromium headless randr

Ubuntu

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:    14.04
Codename:   trusty
Run Code Online (Sandbox Code Playgroud)

chromium-browser --version
Chromium 48.0.2564.116 Ubuntu 14.04
Run Code Online (Sandbox Code Playgroud)

我正在为 Flask Web 应用程序提供服务localhost,我想以无头模式浏览它。

stackoverflow 上跟随这条线索

先决条件

$ apt-get install xvfb imagemagick
Run Code Online (Sandbox Code Playgroud)

X 虚拟帧缓冲区 xvfb-run

使用以下选项运行Chromium

--allow-running-insecure-content    // trying to get passed
--ignore-certificate-errors         // the self-signed certs
--ignore-urlfetcher-cert-requests   //
--disable-gpu                       
--no-sandbox                        
Run Code Online (Sandbox Code Playgroud)

命令

 xvfb-run --server-args='-screen 0, 1024x768x24' chromium-browser --allow-running-insecure-content --ignore-certificate-errors --ignore-urlfetcher-cert-requests  --disable-gpu --no-sandbox https://admin:password@localhost
Run Code Online (Sandbox Code Playgroud)

Xlib:显示“:99”上缺少扩展“RANDR”。

[2596:2596:0407/170544:ERROR:browser_main_loop.cc(206)] Running without the SUID sandbox! See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
Xlib:  extension "RANDR" missing on display ":99".
Xlib:  extension "RANDR" missing on display ":99".
[2596:2596:0407/170544:ERROR:desktop_window_tree_host_x11.cc(892)] Not implemented reached in virtual void views::DesktopWindowTreeHostX11::InitModalType(ui::ModalType)
[2596:2596:0407/170545:ERROR:logging.h(808)] Failed to call method: org.freedesktop.DBus.ObjectManager.GetManagedObjects: object_path= /: org.freedesktop.DBus.Error.UnknownMethod: Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist
[2596:2596:0407/170545:ERROR:logging.h(808)] Failed to call method: org.freedesktop.DBus.ObjectManager.GetManagedObjects: object_path= /: org.freedesktop.DBus.Error.UnknownMethod: Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist
[2596:2596:0407/170629:ERROR:chrome_browser_main_extra_parts_x11.cc(62)] X IO error received (X server probably went away)
Run Code Online (Sandbox Code Playgroud)

没有--disable-gpu--no-sandbox

[3122:3122:0407/172728:ERROR:sandbox_linux.cc(338)] InitializeSandbox() called with multiple threads in process gpu-process
[3062:3099:0407/172728:ERROR:browser_gpu_channel_host_factory.cc(144)] Failed to create channel.
Run Code Online (Sandbox Code Playgroud)

更新 20160407

$ sudo Xvfb :1 -screen 0 1024x768x24 -ac +extension GLX +extension RANDR +render -noreset &
$ export DISPLAY=":1"
$ chromium-browser --allow-running-insecure-content --ignore-certificate-errors --ignore-urlfetcher-cert-requests  --disable-gpu --no-sandbox https://admin:password@localhost
Run Code Online (Sandbox Code Playgroud)

得到

[3413:3413:0407/174058:ERROR:browser_main_loop.cc(206)] Running without the SUID sandbox! See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for more information on developing with the sandbox on.
[3413:3413:0407/174058:ERROR:browser_main_loop.cc(256)] Gtk: cannot open display: :1
[3422:3422:0100/000000:ERROR:zygote_linux.cc(674)] write: Broken pipe
Run Code Online (Sandbox Code Playgroud)

也试过 google-chrome

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - 
sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update 
sudo apt-get install google-chrome-stable
Run Code Online (Sandbox Code Playgroud)

版本

google-chrome --version
Google Chrome 49.0.2623.110 
Run Code Online (Sandbox Code Playgroud)

我收到了同样的错误,包括 extension "RANDR" missing on display ":99".

相关文章

以任何方式启动 google-chrome-in-headless-mode

如何添加缺少的randr扩展

无法启动 chrome-ubuntu

Ser*_*rie 11

我在非 Ubuntu Linux 发行版上做了类似的事情。出于测试目的,我将使用我的 HTPC 运行 Ubuntu (14.04) 以确保它在那里也能以最少的更改工作。

发行信息

htpc@HTPC:[~]:$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:        14.04
Codename:       trusty
Run Code Online (Sandbox Code Playgroud)

确保我们要使用的显示器尚不存在

htpc@HTPC:[~]:$ DISPLAY=:1 xset q
xset:  unable to open display ":1"
Run Code Online (Sandbox Code Playgroud)

启动 Xvfb

不需要sudo。我以同样启动浏览器的用户身份运行它。

Xvfb :1 -screen 0 '1280x1024x16' -ac &> /dev/null &
Run Code Online (Sandbox Code Playgroud)

确保显示器在场并归您所有

htpc@HTPC:[~]:$ ls -l /tmp/.X11-unix/X1
srwxrwxrwx 1 htpc htpc 0 Apr 15 11:37 /tmp/.X11-unix/X1
Run Code Online (Sandbox Code Playgroud)

将当前显示导出到我们刚刚创建的:1

我们还可以在要在显示器上运行的每个命令之前添加DISPLAY=:1。但是,导出可确保为当前会话保存此信息,因此您不必为每个命令都提供它。

export DISPLAY=:1
Run Code Online (Sandbox Code Playgroud)

另一项检查以确保屏幕存在并且正在工作(并且导出位正在工作)

htpc@HTPC:[~]:$ xset q
Keyboard Control:
  auto repeat:  on    key click percent:  0    LED mask:  00000000
  XKB indicators:
    00: Caps Lock:   off    01: Num Lock:    off    02: Scroll Lock: off
    03: Compose:     off    04: Kana:        off    05: Sleep:       off
    06: Suspend:     off    07: Mute:        off    08: Misc:        off
    09: Mail:        off    10: Charging:    off    11: Shift Lock:  off
    12: Group 2:     off    13: Mouse Keys:  off
  auto repeat delay:  660    repeat rate:  25
  auto repeating keys:  00ffffffdffffbbf
                        fadfffefffedffff
                        9fffffffffffffff
                        fff7ffffffffffff
  bell percent:  50    bell pitch:  400    bell duration:  100
Pointer Control:
  acceleration:  2/1    threshold:  4
Screen Saver:
  prefer blanking:  yes    allow exposures:  yes
  timeout:  600    cycle:  600
Colors:
  default colormap:  0x20    BlackPixel:  0x0    WhitePixel:  0xffff
Font Path:
  /usr/share/fonts/X11/misc,/usr/share/fonts/X11/Type1,built-ins
DPMS (Energy Star):
  Display is not capable of DPMS
Run Code Online (Sandbox Code Playgroud)

额外的调试步骤

我将运行nc,如果 Chrome 尝试联系它,它将详细打印。所以我们会知道这个设置是否有效。另一种方法是在同一显示器上运行VNC服务器并连接到它,这样您就可以看到浏览器正在做什么以及Chrome是否正常启动。我会推荐!Chrome可能会在 UI 中给出不同的错误,在您的情况下,这些错误在控制台中是看不到的。

htpc@HTPC:[~]:$ echo Testing... | nc -l 9999 -v &
[2] 8416
htpc@HTPC:[~]:$ Listening on [0.0.0.0] (family 0, port 9999)
Run Code Online (Sandbox Code Playgroud)

是时候启动Chrome 了

htpc@HTPC:[~]:$ google-chrome --disable-gpu 'http://localhost:9999' &
[3] 8512
htpc@HTPC:[~]:$ [8512:8512:0415/115726:ERROR:browser_main_loop.cc(271)] Gtk: Locale not supported by C library.
    Using the fallback 'C' locale.
Xlib:  extension "RANDR" missing on display ":1".
Xlib:  extension "RANDR" missing on display ":1".
Connection from [127.0.0.1] port 9999 [tcp/*] accepted (family 2, sport 40050)
GET / HTTP/1.1
Host: localhost:9999
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Run Code Online (Sandbox Code Playgroud)

正如您在上面看到的RANDR错误它仍然存在,只需忽略它。在它下方,您会看到Chrome(参见 User-Agent 位)对我们启动的nc进程完成的 HTTP 请求。似乎Chrome正在按预期启动并访问提供的 URL。

用 Chromium 做同样的尝试

htpc@HTPC:[~]:$ chromium-browser --disable-gpu 'http://localhost:9999' &
[3] 13108
htpc@HTPC:[~]:$ Xlib:  extension "RANDR" missing on display ":1".
Xlib:  extension "RANDR" missing on display ":1".
[13108:13108:0415/145854:ERROR:logging.h(813)] Failed to call method: org.freedesktop.DBus.ObjectManager.GetManagedObjects: object_path= /: org.freedesktop.DBus.Error.UnknownMethod: Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist

Connection from [127.0.0.1] port 9999 [tcp/*] accepted (family 2, sport 40542)
[13108:13108:0415/145854:ERROR:logging.h(813)] Failed to call method: org.freedesktop.DBus.ObjectManager.GetManagedObjects: object_path= /: org.freedesktop.DBus.Error.UnknownMethod: Method "GetManagedObjects" with signature "" on interface "org.freedesktop.DBus.ObjectManager" doesn't exist

GET / HTTP/1.1
Host: localhost:9999
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/49.0.2623.108 Chrome/49.0.2623.108 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
Run Code Online (Sandbox Code Playgroud)

这样做具有几乎相同的效果,但还有一些其他警告。正如预期的那样,用户代理是 Chromium。

额外的

如果您想让它保持运行,请不要忘记为每个进程发出disown命令并让它们在后台运行,以确保它们在您注销时不会被杀死。有关disown 的更多信息,请参见http://www.cyberciti.biz/faq/unix-linux-disown-command-examples-usage-syntax/


归档时间:

查看次数:

21165 次

最近记录:

10 年 前