Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Headless Chrome in Chrome 60 on Windows 10?

I've been looking at the following article about Headless Chrome:
https://developers.google.com/web/updates/2017/04/headless-chrome

I just upgraded Chrome on Windows 10 to version 60, but when I run either of the following commands from the command line, nothing seems to happen:

chrome --headless --disable-gpu --dump-dom https://www.google.com/ chrome --headless --disable-gpu --print-to-pdf https://www.google.com/ 

And I'm running all of these commands from the following path (the default installation path for Chrome on Windows):

C:\Program Files (x86)\Google\Chrome\Application\ 

When I run the commands, something seems to process for a second, but I don't actually see anything. What am I doing wrong?
Thanks.


Edit:

As noted by Mark Rajcok, if you add --enable-logging to the --dump-dom command, it works. Also, the --print-to-pdf command works as well in Chrome 61.0.3163.79, but you'll probably have to specify a different path for the output file in order to have the necessary permissions to save it.

As such, the following two commands worked for me:

"C:\Program Files (x86)\Google\Chrome\Application\chrome" --headless --disable-gpu --enable-logging --dump-dom https://www.google.com/ "C:\Program Files (x86)\Google\Chrome\Application\chrome" --headless --disable-gpu --print-to-pdf=D:\output.pdf https://www.google.com/ 

I guess the next step is being able to step through the dumped DOM like PhantomJS with DOM selectors and whatnot, but I suppose that's a separate question.


Edit #2:

For what it's worth, I recently came across a Node API for Headless Chrome called Puppeteer (https://github.com/GoogleChrome/puppeteer), which is really easy to use and delivers all the power of Headless Chrome. If you're looking for an easy way to use Headless Chrome, I highly recommend it.

like image 373
HartleySan Avatar asked Jul 28 '17 02:07

HartleySan


People also ask

How do I run Chrome headless in Windows?

Which command starts the Google Chrome web browser in headless mode? You want to use the “–headless” argument in the command line to start Google Chrome Canary in headless mode.

Is Chrome 60 is a headless web browser?

Starting with version 60, the Chrome browser introduced the ability to run in headless mode. We now have the ability to launch the browser without creating a visual browser window.

How do I run Chromedriver headless?

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.

What version of Chrome is headless browser?

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.


1 Answers

This works for me:

start chrome --enable-logging --headless --disable-gpu --print-to-pdf=c:\misc\output.pdf https://www.google.com/ 

... but only with "start chrome" and "--enable-logging" and with a path (for the pdf) specified - and if the folder "misc" exists on the c-directory.

Addition: ... the path for the pdf - "c:\misc" above - can of course be replaced with any other folder/dir.

like image 107
Marrix Avatar answered Oct 02 '22 16:10

Marrix