Chrome headless:超时退出

Chrome headless: exit on timeout

我正在使用 chrome headless 截屏。但是当添加超时时,进程不会退出,它仍然存在......有没有办法在错误(如超时)时终止进程?

没有超时的命令及其输出(这个有效):

>>> chrome --headless --screenshot --no-sandbox https://whosebug.com
[0808/174530.681784:ERROR:gpu_process_transport_factory.cc(1016)] Lost UI shared context.
Fontconfig warning: "/etc/fonts/fonts.conf", line 146: blank doesn't take any effect anymore. please remove it from your fonts.conf
[0808/174531.735502:ERROR:cert_verify_proc_nss.cc(981)] CERT_PKIXVerifyCert for securepubads.g.doubleclick.net failed err=-8179
[0808/174532.060892:INFO:headless_shell.cc(590)] Written to file screenshot.png.
>>> 

带超时的命令(测试时为 1 毫秒)及其输出(待定):

>>> chrome --headless --screenshot --no-sandbox --timeout=1 https://whosebug.com
[0808/174256.720003:ERROR:gpu_process_transport_factory.cc(1016)] Lost UI shared context.
Fontconfig warning: "/etc/fonts/fonts.conf", line 146: blank doesn't take any effect anymore. please remove it from your fonts.conf
[0808/174256.772496:INFO:headless_shell.cc(344)] Timeout.

我更喜欢使用 Linux 命令 timeout。这是您案例的示例,等待 60 秒然后终止 chrome 实例。

>>> timeout 60 chrome --headless --screenshot --no-sandbox https://whosebug.com