Pablo Gallardo's Blog
My professional web log about SAP and IT
 

How to set up Headless Chrome on Mac

Headless Chrome is a tool to run Chrome web browser without UI. It is inspired in now defunct PhantomJS project.

Headless Chrome is always run in command-line mode. It is limited as all the instructions must be set in the same line, so if we need to add some programming to Headless Chrome we need to search for programming libraries.

Puppeteer is a Node.js library developed by Google team that provides a high-level API to control headless (or full) Chrome.

Node.js is a tool for building fast network applications. It’s known as a “JavaScript runtime environment” which simply means it lets you write JavaScript code that can run on your computer free of any web browser.

NPM is a package manager to install tools that run through the Node.js environment.

Xcode is Apple’s programming environment for macOS. It contains some dependencies that are needed to install Node.js and NPM.

brew is a tool to install other applications in your computer. It will be used to install Node.js (though it has its own installer) because of its cleaner installation.

Set-up Steps

Install Node.js

Open Apple Store, search Xcode and install it.

Install brew

Open terminal and type:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install Node.js and NPM

Open terminal and type:

brew install node

Install Puppeteer

Open terminal and type:

npm i --save puppeteer

Test Puppeteer file

Copy the content above in an editor (as CotEditor) and save it as a file with .js extension (like ‘example.js’).

As you may see, this JavaScript file calls pupeeteer library.

Open terminal, go to the folder where .js file is located and type the following command in order to open file with Node.js:

node example.js

Output should be something like:

HeadlessChrome/73.0.3679.0

Sources

pmgallardo

About pmgallardo

I studied Computer Science at University of Salamanca. Since then, I have been working first as developer and then as SAP consutant. This blog is about problems I dealt when using computers, and more important, the solutions I found. Whenever I am on an issue and suddenlly I have a flash that leads me to a solution, I document my discoveries in a post.

, , , , , , , , , , , , , ,

No comments yet.

Leave a Reply

Política de privacidad