Ένας βήμα προς βήμα οδηγός για την εγκατάσταση του Headless Chromium σε Ubuntu και CentOS.
Πίνακας περιεχομένων
Τι είναι το Headless Chrome;
Το Headless Chrome είναι σαν να τρέχετε ένα πρόγραμμα περιήγησης chrome χωρίς UI (πρόγραμμα περιήγησης), δηλαδή, εκτελείται σε περιβάλλον χωρίς κεφαλές, το οποίο είναι πολύ χρήσιμο για την εκτέλεση αυτοματοποιημένων δοκιμών.
Λοιπόν, τι μας ξεκλειδώνει ο ακέφαλος Chrome;
Ένα από τα πιο συναρπαστικά πράγματα είναι η δυνατότητα δοκιμής των πιο πρόσφατων και σπουδαιότερων χαρακτηριστικών της πλατφόρμας Ιστού, όπως οι μονάδες ES6, οι εργαζόμενοι σε υπηρεσίες και οι ροές. Με το headless chrome, μπορείτε να γράψετε εφαρμογές και να δοκιμάσετε αυτές τις εφαρμογές με ενημερωμένη απόδοση. Το άλλο πράγμα που ξεκλειδώνει είναι αυτές οι φοβερές λειτουργίες όπως ο περιορισμός δικτύου, η εξομοίωση συσκευής και η κάλυψη κώδικα.
Με το headless chrome, μπορείτε να εκτελέσετε δοκιμές χωρίς καν να γράψετε μια γραμμή κώδικα, δεν είναι τόσο ωραίο!
Μπορείτε απλώς να τα εκτελέσετε μέσω της γραμμής εντολών. Παρακάτω είναι μερικές από τις ευρέως χρησιμοποιούμενες σημαίες.
--screenshot #to take a screenshot --print-to-pdf #converting <a href="https://grtechpc.org.com/webpage-to-pdf-tools/">webpage to PDF</a> --dump-dom #dump DOM (document object model) data
Σημείωση – αυτό είναι διαφορετικό από το πρόγραμμα περιήγησης Chromium.
Εγκατάσταση Chromium στο Ubuntu
Βήμα 1: Ενημερώστε το Ubuntu
Στην αρχή, ενημερώστε τα πακέτα στο Ubuntu.
[email protected]:~$ sudo apt-get update Hit:1 https://download.docker.com/linux/ubuntu bionic InRelease Hit:2 http://security.ubuntu.com/ubuntu cosmic-security InRelease Hit:3 http://ppa.launchpad.net/ansible/ansible/ubuntu cosmic InRelease Hit:5 http://apt.puppetlabs.com bionic InRelease Ign:6 http://pkg.jenkins.io/debian-stable binary/ InRelease Hit:7 http://us.archive.ubuntu.com/ubuntu cosmic InRelease Hit:8 http://ppa.launchpad.net/canonical-chromium-builds/stage/ubuntu cosmic InRelease Hit:9 http://pkg.jenkins.io/debian-stable binary/ Release Hit:10 http://us.archive.ubuntu.com/ubuntu cosmic-updates InRelease Hit:11 http://us.archive.ubuntu.com/ubuntu cosmic-backports InRelease Hit:4 https://packages.cloud.google.com/apt kubernetes-xenial InRelease Reading package lists... Done
Βήμα 2: Εγκατάσταση Εξαρτήσεων
Εγκαταστήστε αυτές τις εξαρτήσεις που απαιτούνται για την εγκατάσταση.
[email protected]:~$ sudo apt-get install -y libappindicator1 fonts-liberation Reading package lists... Done Building dependency tree Reading state information... Done fonts-liberation is already the newest version (1:1.07.4-7). fonts-liberation set to manually installed. The following package was automatically installed and is no longer required: chromium-codecs-ffmpeg-extra Use 'sudo apt autoremove' to remove it. The following additional packages will be installed: libdbusmenu-gtk4 libindicator7 Suggested packages: indicator-application The following NEW packages will be installed: libappindicator1 libdbusmenu-gtk4 libindicator7 0 upgraded, 3 newly installed, 0 to remove and 238 not upgraded. Need to get 68.2 kB of archives. After this operation, 280 kB of additional disk space will be used. Get:1 http://us.archive.ubuntu.com/ubuntu cosmic/universe amd64 libdbusmenu-gtk4 amd64 16.04.1+18.10.20180917-0ubuntu1 [27.1 kB] Get:2 http://us.archive.ubuntu.com/ubuntu cosmic/universe amd64 libindicator7 amd64 16.10.0+18.04.20180321.1-0ubuntu1 [21.7 kB] Get:3 http://us.archive.ubuntu.com/ubuntu cosmic/universe amd64 libappindicator1 amd64 12.10.1+18.04.20180322.1-0ubuntu1 [19.4 kB] Fetched 68.2 kB in 1s (61.1 kB/s) Selecting previously unselected package libdbusmenu-gtk4:amd64. (Reading database ... 318270 files and directories currently installed.) Preparing to unpack .../libdbusmenu-gtk4_16.04.1+18.10.20180917-0ubuntu1_amd64.deb ... Unpacking libdbusmenu-gtk4:amd64 (16.04.1+18.10.20180917-0ubuntu1) ... Selecting previously unselected package libindicator7. Preparing to unpack .../libindicator7_16.10.0+18.04.20180321.1-0ubuntu1_amd64.deb ... Unpacking libindicator7 (16.10.0+18.04.20180321.1-0ubuntu1) ... Selecting previously unselected package libappindicator1. Preparing to unpack .../libappindicator1_12.10.1+18.04.20180322.1-0ubuntu1_amd64.deb ... Unpacking libappindicator1 (12.10.1+18.04.20180322.1-0ubuntu1) ... Setting up libindicator7 (16.10.0+18.04.20180321.1-0ubuntu1) ... Setting up libdbusmenu-gtk4:amd64 (16.04.1+18.10.20180917-0ubuntu1) ... Processing triggers for libc-bin (2.28-0ubuntu1) ... Setting up libappindicator1 (12.10.1+18.04.20180322.1-0ubuntu1) ... Processing triggers for libc-bin (2.28-0ubuntu1) ... libappindicator1: This library is used to export menu by an application into a panel fonts-liberation: This library has similar font metrics as Arial, Times and Courier
Μπορεί να υπάρχουν περιπτώσεις όπου θα λείπουν λίγες εξαρτήσεις για την εγκατάσταση του Chrome. Έτσι, εκτελέστε την παρακάτω εντολή, θα εγκαταστήσει όλες τις εξαρτήσεις που λείπουν που απαιτούνται για την εγκατάσταση του χρωμίου.
[email protected]:~$ sudo apt-get install -f The following additional packages will be installed: at-spi2-core cpp cpp-7 dconf-gsettings-backend dconf-service gcc-7-base glib-networking glib-networking-common glib-networking-services gsettings-desktop-schemas libappindicator3-1 libasound2 libasound2-data libatk-bridge2.0-0 libatspi2.0-0 libauthen-sasl-perl libcairo-gobject2 libcolord2 libdata-dump-perl libdbusmenu-gtk3-4 libdconf1 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libencode-locale-perl libepoxy0 libfile-basedir-perl libfile-desktopentry-perl libfile-listing-perl libfile-mimeinfo-perl libfont-afm-perl libfontenc1 libgl1 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libglvnd0 libglx-mesa0 libglx0 libgtk-3-0 libgtk-3-bin libgtk-3-common libhtml-form-perl libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl libhttp-cookies-perl libhttp-daemon-perl libhttp-date-perl libhttp-message-perl libhttp-negotiate-perl libice6 libindicator3-7 libio-html-perl libio-socket-ssl-perl libipc-system-simple-perl libisl19 libjson-glib-1.0-0 libjson-glib-1.0-common liblcms2-2 libllvm9 liblwp-mediatypes-perl liblwp-protocol-https-perl libmailtools-perl libmpc3 libnet-dbus-perl libnet-http-perl libnet-smtp-ssl-perl libnet-ssleay-perl libnspr4 libnss3 libpciaccess0 libproxy1v5 librest-0.7-0 libsensors4 libsm6 libsoup-gnome2.4-1 libsoup2.4-1 libtie-ixhash-perl libtimedate-perl libtry-tiny-perl liburi-perl libwayland-client0 libwayland-cursor0 libwayland-egl1 libwww-perl libwww-robotrules-perl libx11-protocol-perl libx11-xcb1 libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-shape0 libxcb-sync1 libxft2 libxkbcommon0 libxml-parser-perl libxml-twig-perl libxml-xpathengine-perl libxmu6 libxpm4 libxshmfence1 libxss1 libxt6 libxtst6 libxv1 libxxf86dga1 libxxf86vm1 perl-openssl-defaults x11-common x11-utils x11-xserver-utils xdg-utils Suggested packages: cpp-doc gcc-7-locales indicator-application libasound2-plugins alsa-utils libdigest-hmac-perl libgssapi-perl colord gvfs liblcms2-utils libcrypt-ssleay-perl lm-sensors libauthen-ntlm-perl libunicode-map8-perl libunicode-string-perl xml-twig-tools mesa-utils nickle cairo-5c xorg-docs-core The following NEW packages will be installed: at-spi2-core cpp cpp-7 dconf-gsettings-backend dconf-service gcc-7-base glib-networking glib-networking-common glib-networking-services gsettings-desktop-schemas libappindicator3-1 libasound2 libasound2-data libatk-bridge2.0-0 libatspi2.0-0 libauthen-sasl-perl libcairo-gobject2 libcolord2 libdata-dump-perl libdbusmenu-gtk3-4 libdconf1 libdrm-amdgpu1 libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libencode-locale-perl libepoxy0 libfile-basedir-perl libfile-desktopentry-perl libfile-listing-perl libfile-mimeinfo-perl libfont-afm-perl libfontenc1 libgl1 libgl1-mesa-dri libgl1-mesa-glx libglapi-mesa libglvnd0 libglx-mesa0 libglx0 libgtk-3-0 libgtk-3-bin libgtk-3-common libhtml-form-perl libhtml-format-perl libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl libhttp-cookies-perl libhttp-daemon-perl libhttp-date-perl libhttp-message-perl libhttp-negotiate-perl libice6 libindicator3-7 libio-html-perl libio-socket-ssl-perl libipc-system-simple-perl libisl19 libjson-glib-1.0-0 libjson-glib-1.0-common liblcms2-2 libllvm9 liblwp-mediatypes-perl liblwp-protocol-https-perl libmailtools-perl libmpc3 libnet-dbus-perl libnet-http-perl libnet-smtp-ssl-perl libnet-ssleay-perl libnspr4 libnss3 libpciaccess0 libproxy1v5 librest-0.7-0 libsensors4 libsm6 libsoup-gnome2.4-1 libsoup2.4-1 libtie-ixhash-perl libtimedate-perl libtry-tiny-perl liburi-perl libwayland-client0 libwayland-cursor0 libwayland-egl1 libwww-perl libwww-robotrules-perl libx11-protocol-perl libx11-xcb1 libxaw7 libxcb-dri2-0 libxcb-dri3-0 libxcb-glx0 libxcb-present0 libxcb-shape0 libxcb-sync1 libxft2 libxkbcommon0 libxml-parser-perl libxml-twig-perl libxml-xpathengine-perl libxmu6 libxpm4 libxshmfence1 libxss1 libxt6 libxtst6 libxv1 libxxf86dga1 libxxf86vm1 perl-openssl-defaults x11-common x11-utils x11-xserver-utils xdg-utils 0 upgraded, 117 newly installed, 0 to remove and 58 not upgraded. 1 not fully installed or removed. Need to get 40.7 MB of archives. After this operation, 369 MB of additional disk space will be used. Do you want to continue? [Y/n] Y Fetched 40.7 MB in 4s (9470 kB/s) Extracting templates from packages: 100%
Βήμα 3: Κατεβάστε το Chrome
Κατεβάστε το πακέτο google chrome stable για το σύστημα Ubuntu.
[email protected]:~$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb --2020-01-15 13:58:41-- https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb Resolving dl.google.com (dl.google.com)... 172.217.163.78, 2404:6800:4007:80c::200e Connecting to dl.google.com (dl.google.com)|172.217.163.78|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 62204098 (59M) [application/x-debian-package] Saving to: ‘google-chrome-stable_current_amd64.deb’ google-chrome-stable_current_amd64. 100%[=================================================================>] 59.32M 11.1MB/s in 29s 2020-01-15 13:59:10 (2.04 MB/s) - ‘google-chrome-stable_current_amd64.deb’ saved [62204098/62204098]
Βήμα 4: Εγκαταστήστε το Chrome
Εγκαταστήστε το σταθερό πακέτο.
[email protected]:~$ sudo dpkg -i google-chrome*.deb Selecting previously unselected package google-chrome-stable. (Reading database ... 318285 files and directories currently installed.) Preparing to unpack google-chrome-stable_current_amd64.deb ... Unpacking google-chrome-stable (79.0.3945.117-1) ... Setting up google-chrome-stable (79.0.3945.117-1) ... update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/x-www-browser (x-www-browser) in auto mode update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/gnome-www-browser (gnome-www-browser) in auto mode update-alternatives: using /usr/bin/google-chrome-stable to provide /usr/bin/google-chrome (google-chrome) in auto mode Processing triggers for gnome-menus (3.13.3-11ubuntu2) ... Processing triggers for desktop-file-utils (0.23-3ubuntu2) ... Processing triggers for mime-support (3.60ubuntu1) ... Processing triggers for man-db (2.8.4-2) ...
Βήμα 5: Ελέγξτε την έκδοση Chrome
Για να επιβεβαιώσετε ότι η εγκατάσταση ολοκληρώθηκε με επιτυχία, ελέγξτε την έκδοση του Google Chrome.
[email protected]:~$ google-chrome-stable -version Google Chrome 79.0.3945.117
Προαιρετικά: Εκτελέστε το Chrome Headless
Επιτρέψτε μου να σας δείξω ένα παράδειγμα λειτουργίας του chrome σε λειτουργία χωρίς κεφαλή.
Θα τρέξω το chrome σε λειτουργία χωρίς κεφαλή και όλο το περιεχόμενο του https://gf.dev/ θα αποθηκευτεί ως αρχείο pdf.
[email protected]:~$ google-chrome-stable --headless --disable-gpu --print-to-pdf https://gf.dev/ [0115/140930.772108:INFO:headless_shell.cc(620)] Written to file output.pdf.
Μπορείτε να δείτε ένα αρχείο output.pdf
[email protected]:~$ ls -l out* -rw------- 1 grtechpc.org grtechpc.org 80799 Jan 15 14:09 output.pdf [email protected]:~$
Στη συνέχεια, θα σας δείξω πώς να κάνετε την ίδια ρύθμιση στο σύστημα CentOS.
Εγκατάσταση Chromium στο CentOS
Βήμα 1: Ενημερώστε το CentOS
Ενημερώστε το σύστημα CentOS με την παρακάτω εντολή.
[[email protected] ~]$ sudo yum update
Βήμα 2: Δημιουργία αποθετηρίου Chrome
Προσθέστε το αποθετήριο google chrome στο σύστημα. Δημιουργήστε ένα αρχείο google-chrome.repo μέσα στο /etc/yum.repos.d/ και προσθέστε τις λεπτομέρειες παρακάτω.
[[email protected] ~]$ sudo gedit /etc/yum.repos.d/google-chrome.repo [google-chrome] name=google-chrome baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch enabled=1 gpgcheck=1 gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
Βήμα 3: Εγκαταστήστε το Chrome
Εκτελέστε την παρακάτω εντολή yum για να εγκαταστήσετε το google chrome στο σύστημα CentOS.
[[email protected] ~]$ sudo yum install google-chrome-stable Last metadata expiration check: 0:04:04 ago on Wed 22 Jan 2020 01:06:24 PM EST. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: google-chrome-stable x86_64 79.0.3945.130-1 google-chrome 60 M Installing dependencies: libXScrnSaver x86_64 1.2.3-1.el8 AppStream 31 k libappindicator-gtk3 x86_64 12.10.0-19.el8 AppStream 43 k libdbusmenu x86_64 16.04.0-12.el8 AppStream 140 k libdbusmenu-gtk3 x86_64 16.04.0-12.el8 AppStream 41 k libindicator-gtk3 x86_64 12.10.1-14.el8 AppStream 70 k liberation-fonts noarch 1:2.00.3-4.el8 BaseOS 19 k liberation-serif-fonts noarch 1:2.00.3-4.el8 BaseOS 607 k Transaction Summary ================================================================================ Install 8 Packages Total download size: 60 M Installed size: 213 M Is this ok [y/N]: y Downloading Packages: (1/8): libXScrnSaver-1.2.3-1.el8.x86_64.rpm 146 kB/s | 31 kB 00:00 (2/8): libappindicator-gtk3-12.10.0-19.el8.x86_ 171 kB/s | 43 kB 00:00 (3/8): libdbusmenu-gtk3-16.04.0-12.el8.x86_64.r 691 kB/s | 41 kB 00:00 (4/8): libindicator-gtk3-12.10.1-14.el8.x86_64. 558 kB/s | 70 kB 00:00 (5/8): liberation-fonts-2.00.3-4.el8.noarch.rpm 74 kB/s | 19 kB 00:00 (6/8): liberation-serif-fonts-2.00.3-4.el8.noar 1.3 MB/s | 607 kB 00:00 (7/8): libdbusmenu-16.04.0-12.el8.x86_64.rpm 121 kB/s | 140 kB 00:01 (8/8): google-chrome-stable-79.0.3945.130-1.x86 8.4 MB/s | 60 MB 00:07 -------------------------------------------------------------------------------- Total 6.5 MB/s | 60 MB 00:09 warning: /var/cache/dnf/google-chrome-eb0d6f10ccbdafba/packages/google-chrome-stable-79.0.3945.130-1.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 7fac5991: NOKEY google-chrome 49 kB/s | 10 kB 00:00 Importing GPG key 0x7FAC5991: Userid : "Google, Inc. Linux Package Signing Key <[email protected]>" Fingerprint: 4CCA 1EAF 950C EE4A B839 76DC A040 830F 7FAC 5991 From : https://dl-ssl.google.com/linux/linux_signing_key.pub Is this ok [y/N]: y Key imported successfully Importing GPG key 0xD38B4796: Userid : "Google Inc. (Linux Packages Signing Authority) <[email protected]>" Fingerprint: EB4C 1BFD 4F04 2F6D DDCC EC91 7721 F63B D38B 4796 From : https://dl-ssl.google.com/linux/linux_signing_key.pub Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : libdbusmenu-16.04.0-12.el8.x86_64 1/8 Installing : libdbusmenu-gtk3-16.04.0-12.el8.x86_64 2/8 Installing : liberation-serif-fonts-1:2.00.3-4.el8.noarch 3/8 Installing : liberation-fonts-1:2.00.3-4.el8.noarch 4/8 Installing : libindicator-gtk3-12.10.1-14.el8.x86_64 5/8 Installing : libappindicator-gtk3-12.10.0-19.el8.x86_64 6/8 Installing : libXScrnSaver-1.2.3-1.el8.x86_64 7/8 Running scriptlet: google-chrome-stable-79.0.3945.130-1.x86_64 8/8 Installing : google-chrome-stable-79.0.3945.130-1.x86_64 8/8 Running scriptlet: google-chrome-stable-79.0.3945.130-1.x86_64 8/8 Redirecting to /bin/systemctl start atd.service Verifying : libXScrnSaver-1.2.3-1.el8.x86_64 1/8 Verifying : libappindicator-gtk3-12.10.0-19.el8.x86_64 2/8 Verifying : libdbusmenu-16.04.0-12.el8.x86_64 3/8 Verifying : libdbusmenu-gtk3-16.04.0-12.el8.x86_64 4/8 Verifying : libindicator-gtk3-12.10.1-14.el8.x86_64 5/8 Verifying : liberation-fonts-1:2.00.3-4.el8.noarch 6/8 Verifying : liberation-serif-fonts-1:2.00.3-4.el8.noarch 7/8 Verifying : google-chrome-stable-79.0.3945.130-1.x86_64 8/8 Installed: google-chrome-stable-79.0.3945.130-1.x86_64 libXScrnSaver-1.2.3-1.el8.x86_64 libappindicator-gtk3-12.10.0-19.el8.x86_64 libdbusmenu-16.04.0-12.el8.x86_64 libdbusmenu-gtk3-16.04.0-12.el8.x86_64 libindicator-gtk3-12.10.1-14.el8.x86_64 liberation-fonts-1:2.00.3-4.el8.noarch liberation-serif-fonts-1:2.00.3-4.el8.noarch Complete!
Βήμα 4: Ελέγξτε την έκδοση Chrome
Για να επιβεβαιώσετε ότι η εγκατάσταση ολοκληρώθηκε με επιτυχία, ελέγξτε την έκδοση του google chrome.
[[email protected] ~]$ google-chrome -version Google Chrome 79.0.3945.130
Προαιρετικά: Εκτελέστε το Chrome Headless
Επιτρέψτε μου να σας δείξω ένα παράδειγμα λειτουργίας του chrome σε λειτουργία χωρίς κεφαλή στο CentOS.
Θα πάρω το παράδειγμα της λήψης στιγμιότυπου οθόνης. Αυτή η παρακάτω εντολή θα εκτελεί το chrome σε λειτουργία χωρίς κεφαλή και όλο το περιεχόμενο του https://www.chromestatus.com/ θα αποθηκευτεί ως αρχείο pdf.
[[email protected] ~]$ google-chrome-stable --headless --disable-gpu --print-to-pdf https://www.chromestatus.com/ [0122/131602.193881:INFO:headless_shell.cc(620)] Written to file output.pdf.
Δημιουργήθηκε το αρχείο output.pdf το οποίο έχει όλο το περιεχόμενο του https://www.chromestatus.com/
[[email protected] ~]$ ls -l total 61208 drwxr-xr-x. 2 grtechpc.org grtechpc.org 6 Sep 25 11:49 Desktop drwxr-xr-x. 2 grtechpc.org grtechpc.org 6 Sep 25 11:49 Documents drwxr-xr-x. 2 grtechpc.org grtechpc.org 6 Sep 25 11:49 Downloads -rw-rw-r--. 1 grtechpc.org grtechpc.org 180 Jan 22 13:05 google-chrome.repo -rw-------. 1 grtechpc.org grtechpc.org 146776 Jan 22 13:16 output.pdf
Αυτό αφορούσε το πώς να εγκαταστήσετε το Chrome σε Ubuntu & CentOS και να το εκτελέσετε σε λειτουργία χωρίς κεφαλή.