Chrome Headless无法正常运作 [英] Chrome Headless Doesn't work

查看:610
本文介绍了Chrome Headless无法正常运作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已从 developers.google 阅读有关Chrome无头的内容说我们可以在没有UI的情况下运行Google.从该链接引用:

I've read about the Chrome Headless from developers.google said we can run the Google without UI. Quote from that link :

Chrome 59附带了无头Chrome.这是运行Chrome的一种方式 无头环境中的浏览器.本质上,在没有 铬合金!它带来了由...提供的所有现代网络平台功能 将Chromium和Blink渲染引擎添加到命令行.

Headless Chrome is shipping in Chrome 59. It's a way to run the Chrome browser in a headless environment. Essentially, running Chrome without chrome! It brings all modern web platform features provided by Chromium and the Blink rendering engine to the command line.

为什么有用?

无头浏览器是用于自动化测试和服务器的出色工具 您不需要可见的UI Shell的环境.例如,你 可能想对一个真实的网页运行一些测试,创建一个PDF 它,或者只是检查浏览器如何呈现URL.

A headless browser is a great tool for automated testing and server environments where you don't need a visible UI shell. For example, you may want to run some tests against a real web page, create a PDF of it, or just inspect how the browser renders an URL.

这真的是一个很棒的功能,所以我对这个很酷的功能做了一些实验.想法是通过Windows命令提示符下的chrome.exe调用,将快照作为文档站点,如下所示:

This is really great feature, so I do some experiment with this cool feature. The idea is to taking snapshot as the document site by do call of chrome.exe from Windows Command Prompt, as follow :

chrome --headless --disable-gpu --screenshot https://www.chromestatus.com/

执行几次后,并按照这些站点上的说明进行操作.我一无所获.我没有得到任何名称为screenshot.png的图片或屏幕截图,正如文档在Running with --screenshot will produce a file named screenshot.png in the current working directory.

After do several times and following the instruction from these site. I got nothing. I don't get any picture or screenshot with name screenshot.png as document mention it before Running with --screenshot will produce a file named screenshot.png in the current working directory.

从本文档还说了有关版本,

From this document also said about version,

警告:无头模式在Mac和Linux的Chrome 59中可用. Chrome 60即将提供Windows支持.要检查哪个版本的 您拥有的Chrome浏览器,打开chrome://version.

Caution: Headless mode is available on Mac and Linux in Chrome 59. Windows support is coming in Chrome 60. To check what version of Chrome you have, open chrome://version.

经过与建议的检查之后,我在Windows x64 Machine的Chrome上运行chrome://version并得到了一些结果:

after do some check with suggested before, I run chrome://version on my Chrome on Windows x64 Machine and got some result :

Google Chrome   62.0.3202.94 (Official Build) (64-bit) (cohort: Stable)
Revision    4fd852a98d66564c88736c017b0a0b0478e885ad-refs/branch-heads/3202@{#789} 

怎么了?我错过了什么? 谢谢

What wrong? What i missed? Thanks

推荐答案

进行一些实验之后. --screenshot会将图片保存在与chrome.exe位置相同的级别上,这意味着将其保存在Program Files上.

After do some experiments. for --screenshot will save the image on the same level as chrome.exe location and that will be mean save on Program Files.

因此我们需要将参数名称和参数与=组合起来

So we need need to combine parameter names and arguments with a =

-screenshot ="D:\ screen.png"将起作用,否则Chrome将写入其安装文件夹.设计存在重大缺陷,任何软件都不应将其安装文件夹用作工作目录.

--screenshot="D:\screen.png" will work, otherwise Chrome writes to it's installation folder. Big design flaw, no software should use it's installation folder as a working directory.

这里是完整的论点:

chrome --headless --enable-logging --disable-gpu --screenshot="D:\screen.png" "https://www.chromestatus.com/"

这篇关于Chrome Headless无法正常运作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆