Headless browser installation in China is a bit of a bummer because of the great boom, if you can follow the steps on Github and install it successfully, I lose.

Server Centos 7 Install Chrome

It is impossible to install in UI mode, or your server’s command line would be useless. In this mode, the local REPO is set up first.

1. Add Rep source

$ sudo touch /etc/yum.repos.d/google.repo
Copy the code

Open the file using vi and fill it as follows:

[google]
name=Google-x86_64
baseurl=http://dl.google.com/linux/rpm/stable/x86_64
enabled=1
gpgcheck=0
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
Copy the code

2. Yum install

$ sudo yum update
$ sudo yum install google-chrome-stable
Copy the code

3. The installation is successful

Success is always intoxicating!

Downloading packages: (1/11) : libXScrnSaver 1.2.2-6.1 el7. X86_64. RPM | 24 kB 00:00 (2/11) : Libappindicator - gtk3-12.10.0-13. El7. X86_64. RPM | 37 kB 00:00 (3/11) : Libdbusmenu - gtk3-16.04.0-4. El7. X86_64. RPM | 34 kB 00:00 (4/11) : Libdbusmenu 16.04.0-4. El7. X86_64. RPM | 132 kB 00:00 (5/11) : Liberation - fonts - 1.07.2-16. El7. Noarch. RPM | 13 kB 00:00 (6/11) : Liberation - narrow - fonts - 1.07.2-16. El7. Noarch. RPM | 202 kB 00:00 (7/11) : Libindicator - gtk3-12.10.1-6. El7. X86_64. RPM | 63 kB 00:00 (8/11) : Redhat - LSB - submod ws-security - 4.1-27 el7. Centos. 1. X86 | 15 kB 00:00 (9/11) : Redhat - LSB - core - 4.1-27 el7. Centos. 1. X86_64. RPM | 38 kB 00:01onsaturday (UK time) (10/11) : Spax 1.5.2-13. El7. X86_64. RPM | 260 kB 00:01onsaturday (UK time) (11/11) : Google chrome - stable - 78.0.3904.70-1. X86_64. RPM | 61 MB 00:09 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Total 6.2 MB/s | 61 MB 00:09 Installed: Google chrome - stable. X86_64 0:7 8.0.3904.70-1 the Dependency Installed: Libxscrnsaver.x86_64 0:1.2.2-6.1.el7 libappindicator-gtk3.x86_64 0:12.10.0-13.el7 libdbusmenu.x86_64 0:16.04.0-4.el7 Libdbusmenu-gtk3.x86_64 0:16.04.0-4.el7 liberation-fonts. Noarch 1:07.2-16. el7 liberation-narrow-fonts El7 libindicator-gtk3.x86_64 0:12.10.1-6.el7 Redhat-LSB-core.x86_64 0:4.1-27.el7.centos.1 Redhat-lsb-submod-security.x86_64 0:4.1-27.el7.centos.1 spax.x86_64 0:1.5.2-13.el7 Complete!Copy the code

Install nodeJS in Centos

The simple YUM setup is used here, or you can install it however you like.

curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum install -y nodejs
Copy the code

For an upgrade, use the N tool

#Global installation n
$ npm install -g n
#Upgrade to the latest stable version
$ n stable 
#Upgrade to the latest version
$ n latest
#Upgrade to a custom version
$N v7.10.0
#Switching the Version
$N 7.10.0 (ENTER)
Copy the code

Install the puppeteer

Puppeteer, Google’s own son, has direct access to chrome, the headless browser. Do not install Chrome when installing, which server is Google, you will not be able to successfully install.

npm install puppeteer --ignore-scripts
Copy the code

This will be later configured to use Chrome installed above.

All right, let’s hit the ground running

A chestnut

We initialize a project with NPM init and edit index.js

const puppeteer = require('puppeteer');
(async() = > {const browser = await puppeteer.launch({
    // The sandbox is very difficult to match. If you are interested, you can try it.
     args: ["--no-sandbox"].headless:true.// The default installation path of Chrome
     executablePath: '/opt/google/chrome/chrome'.slowMo:100
    });
     const page = await browser.newPage();
     await page.goto('http://baidu.com');
     await page.screenshot({path:'puppeteer.png'});
     awaitbrowser.close(); }) ();Copy the code

Afterword.

Finally, a headless browser. What do you want? That! Only you know!