Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 821
Yohanim Avatar asked Dec 01 '17 19:12

Yohanim


People also ask

How do I run Chrome in headless mode?

Which command starts the google chrome web browser in headless mode? As we have already seen, you just have to add the flag –headless when you launch the browser to be in headless mode. With CLI (Command Line Interface), just write: chrome \<br> – headless \ # Runs Chrome in headless mode.

How do I run Selenium headless in Chrome?

You can run Google Chrome in headless mode simply by setting the headless property of the chromeOptions object to True. Or, you can use the add_argument() method of the chromeOptions object to add the –headless command-line argument to run Google Chrome in headless mode using the Selenium Chrome web driver.

Can headless browser be detected?

There are many ways to detect whether a request is coming from a headless browser, but whether it will be easy to do so depends greatly on how the headless browser is configured. If used for web scraping, hackers do their absolute best to obscure detection.

What is difference between Chrome and Chrome headless?

Headless, means a Web Browser without User Interface. To elaborate, Headless Browsers are those which actually access the Web Page, but the GUI is hidden from the user. A headless browser is just like any other browser, the only difference is we cannot see anything on the screen.


1 Answers

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/"
like image 140
Yohanim Avatar answered Oct 19 '22 14:10

Yohanim