Get more done with the new Google Chrome. A more simple, secure and faster web browser than ever, with Google’s smarts built in. Nov 28, 2021 Download Google Chrome 69 (64-bit) for Windows PC. 100% Safe and Secure Free Download 64-bit Latest Version 2021. Browsers, Internet.
Headless Chromeis shipping in Chrome 59. It's a way to run the Chrome browser in a headless environment.Essentially, runningChrome without chrome! It brings all modern web platform features providedby 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 youdon't need a visible UI shell. For example, you may want to run some tests againsta real web page, create a PDF of it, or just inspect how the browser renders an URL.Note: Headless mode has been available on Mac and Linux since Chrome 59.Windows supportcame in Chrome 60.
Starting Headless (CLI)
The easiest way to get started with headless mode is to open the Chrome binaryfrom the command line. If you've got Chrome 59+ installed, start Chrome with the
--disable-gpuflag if you're runningon Windows. See crbug.com/737678.
chrome should point to your installation of Chrome. The exact location willvary from platform to platform. Since I'm on Mac, I created convenient aliasesfor each version of Chrome that I have installed.
If you're on the stable channel of Chrome and cannot get the Beta, I recommendusing
Download Chrome Canary here.
Command line features
In some cases, you may not need to programmatically script Headless Chrome.There are some useful command line flagsto perform common tasks.
Printing the DOM
--dump-dom flag prints
document.body.innerHTML to stdout:
Create a PDF
--print-to-pdf flag creates a PDF of the page:
To capture a screenshot of a page, use the
--screenshot will produce a file named
screenshot.png in thecurrent working directory. If you're looking for full page screenshots, thingsare a tad more involved. There's a great blogpost from David Schnurr that has you covered. Check outUsing headless Chrome as an automated screenshot tool.
REPL mode (read-eval-print loop)
--repl flag runs Headless in a mode where you can evaluate JS expressionsin the browser, right from the command line:
Debugging Chrome without a browser UI?
When you run Chrome with
--remote-debugging-port=9222, it starts an instancewith the DevTools protocol enabled. Theprotocol is used to communicate with Chrome and drive the headlessbrowser instance. It's also what tools like Sublime, VS Code, and Node use forremote debugging an application. #synergy
Since you don't have browser UI to see the page, navigate to
http://localhost:9222in another browser to check that everything is working. You'll see a list ofinspectable pages where you can click through and see what Headless is rendering:
From here, you can use the familiar DevTools features to inspect, debug, and tweakthe page as you normally would. If you're using Headless programmatically, thispage is also a powerful debugging tool for seeing all the raw DevTools protocolcommands going across the wire, communicating with the browser.
Using programmatically (Node)
Puppeteer is a Node librarydeveloped by the Chrome team. It provides a high-level API to control headless(or full) Chrome. It's similar to other automated testing libraries like Phantomand NightmareJS, but it only works with the latest versions of Chrome.
Among other things, Puppeteer can be used to easily take screenshots, create PDFs,navigate pages, and fetch information about those pages. I recommend the libraryif you want to quickly automate browser testing. It hides away the complexitiesof the DevTools protocol and takes care of redundant tasks like launching adebug instance of Chrome.
Example - print the user agent
Example - taking a screenshot of the page
Check out Puppeteer's documentationto learn more about the full API.
The CRI library
chrome-remote-interfaceis a lower-level library than Puppeteer's API. I recommend it if you want to beclose to the metal and use the DevTools protocol directly.
chrome-remote-interface doesn't launch Chrome for you, so you'll have to takecare of that yourself.
In the CLI section, we started Chrome manually using
--headless --remote-debugging-port=9222. However, to fully automate tests, you'll probablywant to spawn Chrome from your application.
One way is to use
But things get tricky if you want a portable solution that works across multipleplatforms. Just look at that hard-coded path to Chrome :(
Lighthouse is a marveloustool for testing the quality of your web apps. A robust module for launchingChrome was developed within Lighthouse and is now extracted for standalone use.The
chrome-launcher NPM modulewill find whereChrome is installed, set up a debug instance, launch the browser, and kill itwhen your program is done. Best part is that it works cross-platform thanks toNode!
chrome-launcher will try to launch Chrome Canary (if it'sinstalled), but you can change that to manually select which Chrome to use. Touse it, first install from npm:
Example - using
chrome-launcher to launch Headless
Running this script doesn't do much, but you should see an instance ofChrome fire up in the task manager that loaded
about:blank. Remember, therewon't be any browser UI. We're headless.
To control the browser, we need the DevTools protocol!
Retrieving information about the pageWarning: The DevTools protocol can do a ton of interesting stuff, but it can be a bitdaunting at first. I recommend spending a bit of time browsing theDevTools Protocol Viewer, first. Then, move on to the
chrome-remote-interfaceAPI docs to see how it wraps the raw protocol.
Let's install the library:
Example - print the user agent
Results in something like:
Example - check if the site has a web app manifest
Example - extract the
<title> of the page using DOM APIs.
Using Selenium, WebDriver, and ChromeDriver
Right now, Selenium opens a full instance of Chrome. In other words, it's anautomated solution but not completely headless. However, Selenium can beconfigured to run headless Chrome with a little work. I recommendRunning Selenium with Headless Chromeif you want thefull instructions on how to set things up yourself, but I've dropped in someexamples below to get you started.
ChromeDriver 2.32uses Chrome 61 and works well with headless Chrome.
WebDriverIO is a higher level API on top of Selenium WebDriver.
Example: filter CSS features on chromestatus.com
Here are some useful resources to get you started:
- DevTools Protocol Viewer - API reference docs
Google Chrome Version 59 Download
- chrome-remote-interface - nodemodule that wraps the DevTools protocol
- Lighthouse - automated tool for testingweb app quality; makes heavy use of the protocol
- chrome-launcher -node module for launching Chrome, ready for automation
- 'The Headless Web' - Paul Kinlan's great blogpost on using Headless with api.ai.
Do I need the
Only on Windows. Other platforms no longer require it. The
--disable-gpu flag is atemporary work around for a few bugs. You won't need this flag in future versions ofChrome. See crbug.com/737678for more information.
So I still need Xvfb?
No. Headless Chrome doesn't use a window so a display server like Xvfb isno longer needed. You can happily run your automated tests without it.
Google Chrome Version 59 Download 64-bit
What is Xvfb? Xvfb is an in-memory display server for Unix-like systems that enables youto run graphical applications (like Chrome) without an attached physical display.Many people use Xvfb to run earlier versions of Chrome to do 'headless' testing.
How do I create a Docker container that runs Headless Chrome?
Check out lighthouse-ci. It has anexample Dockerfilethat uses
node:8-slim as a base image, installs +runs Lighthouseon App Engine Flex.
--no-sandboxis not needed if youproperly setup a userin the container.
Can I use this with Selenium / WebDriver / ChromeDriver?
Yes. See Using Selenium, WebDrive, or ChromeDriver.
How is this related to PhantomJS?
Headless Chrome is similar to tools like PhantomJS. Bothcan be used for automated testing in a headless environment. The main differencebetween the two is that Phantom uses an older version of WebKit as its renderingengine while Headless Chrome uses the latest version of Blink.
At the moment, Phantom also provides a higher level API than the DevTools protocol.
Where do I report bugs?
For bugs against Headless Chrome, file them on crbug.com.
For bugs in the DevTools protocol, file them at github.com/ChromeDevTools/devtools-protocol.