繁体   English   中英

Chrome Headless不起作用

[英]Chrome Headless Doesn't work

我已经从developers.google中了解到有关Chrome Headless的信息,我们可以在没有用户界面的情况下运行Google。 从该链接引用:

无头Chrome在Chrome 59中发布。这是在无头环境中运行Chrome浏览器的一种方式。 基本上,运行没有铬的Chrome! 它将Chromium和Blink渲染引擎提供的所有现代Web平台功能引入命令行。

为什么这有用?

无头浏览器是自动测试和服务器环境的绝佳工具,您不需要可见的UI shell。 例如,您可能希望针对真实网页运行某些测试,创建PDF,或者仅检查浏览器如何呈现URL。

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

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.之前提及它Running with --screenshot will produce a file named screenshot.png in the current working directory.

从这份文件中也谈到版本,

警告:Chrome 59中的Mac和Linux上提供无头模式.Chrome 60中将提供Windows支持。要查看您的Chrome版本,请打开chrome:// version。

在使用之前的建议进行一些检查后,我在Windows x64计算机上的Chrome上运行chrome://version并获得了一些结果:

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

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

做了一些实验。 for- --screenshot会将图像保存在与chrome.exe位置相同的级别,这将意味着保存在Program Files

所以我们需要将参数名和参数与a组合起来

--screenshot =“D:\\ screen.png”将起作用,否则Chrome会写入其安装文件夹。 大的设计缺陷,没有软件应该使用它的安装文件夹作为工作目录。

以下是完整的论点:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM