Ubuntu

Ubuntu

Ubuntu

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:    14.04
Codename:   trusty

chromium-browser --version
Chromium 48.0.2564.116 Ubuntu 14.04

我正在运行一个 Flask Web 应用程序localhost,并且想以无头模式浏览它。

按照此在 stackoverflow 上领先

先决条件

$ apt-get install xvfb imagemagick

X 虚拟帧缓冲区xvfb-run

跑步使用以下选项

--allow-running-insecure-content    // trying to get passed
--ignore-certificate-errors         // the self-signed certs
--ignore-urlfetcher-cert-requests   //
--disable-gpu                       
--no-sandbox                        

命令

 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

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)

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

更新 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

获得

[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

也尝试过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

版本

google-chrome --version
Google Chrome 49.0.2623.110 

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

相关文章

以任何方式启动 Google Chrome 的无头模式

如何添加缺失的 randr 扩展

无法启动 chrome-ubuntu

答案1

我在非 Ubuntu Linux 发行版上做了类似的事情。为了进行测试,我将使用运行 Ubuntu (14.04) 的 HTPC 来确保它只需进行最少的更改即可在那里正常工作。

发行版信息

htpc@HTPC:[~]:$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:        14.04
Codename:       trusty

确保我们想要使用的显示器尚未出现

htpc@HTPC:[~]:$ DISPLAY=:1 xset q
xset:  unable to open display ":1"

启动 Xvfb

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

Xvfb :1 -screen 0 '1280x1024x16' -ac &> /dev/null &

确保显示器存在且归您所有

htpc@HTPC:[~]:$ ls -l /tmp/.X11-unix/X1
srwxrwxrwx 1 htpc htpc 0 Apr 15 11:37 /tmp/.X11-unix/X1

将当前显示导出至:1我们刚刚创建。

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

export DISPLAY=:1

再次检查以确保屏幕存在且正常工作(并且导出位也正常工作)

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

额外的调试步骤

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

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

开始时间铬合金

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

正如你在上面看到的兰德公司如果错误仍然存​​在,请忽略它。在它下面,你会看到 HTTP 请求由铬合金(参见 User-Agent 位)数控我们开始的过程。似乎铬合金正在按预期启动并访问提供的 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

执行相同操作会产生几乎相同的效果,但会出现一些其他警告。正如预期的那样,User-Agent 是 Chromium。

额外的

如果你想让一切继续运行,不要忘记发出否认每个进程运行一个命令,并让它们在后台运行,以确保它们不会在您注销时被终止。请参阅http://www.cyberciti.biz/faq/unix-linux-disown-command-examples-usage-syntax/了解更多信息否认

相关内容