Skip to content

Instantly share code, notes, and snippets.

@ipepe
Last active April 19, 2024 07:15
Show Gist options
  • Star 77 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save ipepe/94389528e2263486e53645fa0e65578b to your computer and use it in GitHub Desktop.
Save ipepe/94389528e2263486e53645fa0e65578b to your computer and use it in GitHub Desktop.
Installing headless chrome on Ubuntu.
#!/bin/bash
# from https://chromium.woolyss.com/
# and https://gist.github.com/addyosmani/5336747
# and https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:canonical-chromium-builds/stage
sudo apt-get update
sudo apt-get install chromium-browser
chromium-browser --headless --no-sandbox http://example.org/
@Omniscience619
Copy link

Omniscience619 commented Oct 8, 2021

uninstall previous chrome sudo apt-get purge chromium-browser

re-install the new stable chrome headless

sudo apt-get update
sudo apt-get install -y libappindicator1 fonts-liberation
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb

I used these commands in a non-alpine based Dockerfile to setup LightHouse. At first it seemed to work great, but I encountered errors with the Debian package dependencies. After using gdebi-core as an alternative for dpkg, I discovered that the URL given by @putuoka is actually outdated (it's from 2018), so I used the current official URL to download Chrome Headless.

You can refer to my Dockerfile below for references.

FROM node:16
#RUN yes | npm install -g npm@8.0.0
RUN npm install -g lighthouse
RUN apt update
RUN apt-get install -y libappindicator1 fonts-liberation
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt install -y gdebi-core
RUN gdebi --non-interactive google-chrome*.deb

I've successfully installed it. For additional references, you can view the answer by @LoganGray

Thanks to all.

@phd
Copy link

phd commented Nov 25, 2021

@alexkuc
@Kcharle

This ppa repository (https://launchpad.net/~phd/+archive/ubuntu/chromium-browser) was moved (phd.re -> phd):
sudo add-apt-repository ppa:phd/chromium-browser
Since this gist is easily googleable when looking for alternative chromium ppa, could you please update the above in your comments?

Also you will need apt-pinning, as occasionally the original snap package may have higher version than the one in this ppa:

echo '
Package: *
Pin: release o=LP-PPA-phd-chromium-browser
Pin-Priority: 1001
' | sudo tee /etc/apt/preferences.d/phd-chromium-browser

@u007
Copy link

u007 commented Nov 27, 2021

this one works on debian 11

FROM node:14-bullseye

RUN apt-get update && apt-get install -y fonts-liberation
RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
RUN apt update && apt install -y google-chrome-stable

@harryqt
Copy link

harryqt commented Nov 27, 2021

@u007 you are a hero, it also works on Ubuntu 20.04

@u007
Copy link

u007 commented Nov 28, 2021

sorry i also found it somewhere, lost track of it haha

@OleOldhoj
Copy link

I am on a ubuntu ...

and i cant make it work :(

npx lighthouse --chrome-flags='--headless' --quiet --no-update-notifier --no-enable-error-reporting --output=json --throttle --stop --preset=desktop --output-path=\nytimes_com\2022_05_15_01_32_43_R_1_nytimes_com_desktop.json https://www.nytimes.com/
Unable to connect to Chrome

@u007
Copy link

u007 commented May 15, 2022

are you running in docker?

@alexkuc
Copy link

alexkuc commented May 26, 2022

@phd I am more than happy to update my comment. Would you mind providing me a full command so that I can copy & paste as I won't be able to test it anymore?

@phd
Copy link

phd commented May 26, 2022

@alexkuc

sudo add-apt-repository ppa:phd/chromium-browser

echo '
Package: *
Pin: release o=LP-PPA-phd-chromium-browser
Pin-Priority: 1001
' | sudo tee /etc/apt/preferences.d/phd-chromium-browser

sudo apt update

sudo apt install -y chromium-browser

@alexkuc
Copy link

alexkuc commented May 26, 2022

@phd Done, thank you!

@ossentoo
Copy link

ossentoo commented Feb 8, 2023

thanks

@ktechmidas
Copy link

Do yourselves a favour and switch to Microsoft Edge, Chromium underneath and a proper deb package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment