Yohanes AI
Yohanes AI

Reputation: 3619

Chrome Headless Doesn't work

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

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.

Why is that useful?

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.

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/

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,

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.

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

Upvotes: 8

Views: 7650

Answers (1)

Yohanes AI
Yohanes AI

Reputation: 3619

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

Here are the complete argument :

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

Upvotes: 13

Related Questions