
After the installation is finished, create simple script that opens Google Search home page and takes its screenshot in headless mode. npm install -save chromium chromedriver selenium-webdriver.

Type a Javascript expression to evaluate or "quit" to exit. Its extremely easy to use node-chromium with selenium-webdriver to perform e2e tests without spawning browser UI. The -repl flag runs Headless in a mode where you can evaluate JS expressions in the browser, right from the command line: $ chrome -headless -disable-gpu -repl -crash-dumps-dir =./tmp Check out Using headless Chrome as an automated screenshot tool. There's a great blog post from David Schnurr that has you covered. If you're looking for full page screenshots, things are a tad more involved. Running with -screenshot will produce a file named screenshot.png in the current working directory. To capture a screenshot of a page, use the -screenshot flag: chrome -headless -disable-gpu -screenshot Ĭhrome -headless -disable-gpu -screenshot -window-size = 1280,1696 Ĭhrome -headless -disable-gpu -screenshot -window-size = 412,732 The -print-to-pdf flag creates a PDF of the page: chrome -headless -disable-gpu -print-to-pdf # Taking screenshots The -dump-dom flag prints to stdout: chrome -headless -disable-gpu -dump-dom # Create a PDF There are some useful command line flags to perform common tasks. In some cases, you may not need to programmatically script Headless Chrome. If you're on the stable channel of Chrome and cannot get the Beta, I recommend using chrome-canary: alias chrome = "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"Īlias chrome-canary = "/Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary"Īlias chromium = "/Applications/Chromium.app/Contents/MacOS/Chromium"ĭownload Chrome Canary here. Since I'm on Mac, I created convenient aliases for each version of Chrome that I have installed. The exact location will vary from platform to platform. See /737678.Ĭhrome should point to your installation of Chrome. For additional references, you can view the answer by to all.Note: Right now, you'll also want to include the -disable-gpu flag if you're running on Windows. RUN gdebi -non-interactive google-chrome*.deb RUN apt-get install -y libappindicator1 fonts-liberation #RUN yes | npm install -g npm install -g lighthouse You can refer to my Dockerfile below for references. After using gdebi-core as an alternative for dpkg, I discovered that the URL given by is actually outdated (it's from 2018), so I used the current official URL to download Chrome Headless.

At first it seemed to work great, but I encountered errors with the Debian package dependencies. I used these commands in a non-alpine based Dockerfile to setup LightHouse. Sudo apt-get install -y libappindicator1 fonts-liberation Re-install the new stable chrome headless sudo apt-get update Uninstall previous chrome sudo apt-get purge chromium-browser
