Skip to content

Instantly share code, notes, and snippets.

@ipepe
Last active August 20, 2024 23:34
Show Gist options
  • 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/
@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

@ulidtko
Copy link

ulidtko commented Aug 20, 2024

@ktechmidas oh man... That's hilarious, thanks for the great advice!

The only difficulty I had with installing Microsoft Edge + WebDriver into a CI docker — it wasn't easy to contain the primal laughter of me doing such a fun thing — otherwise, it actually went silky smooth! 🤣

Way smoother than dealing with google's utterly borked apt repos, at any rate.

FROM python:3.10

#-- Add Microsoft's deb package signing key -- https://learn.microsoft.com/en-us/linux/packages
RUN wget https://packages.microsoft.com/keys/microsoft.asc -O - \
    | gpg --no-default-keyring --keyring /etc/apt/keyrings/microsoft-packages.gpg --import -

#-- Add APT package repository
RUN echo 'deb [arch=amd64 signed-by=/etc/apt/keyrings/microsoft-packages.gpg] https://packages.microsoft.com/repos/edge stable main' \
    > /etc/apt/sources.list.d/microsoft-edge.list

#-- Refresh index, install latest stable Microsoft Edge
RUN apt-get update && \
    apt-get install -y --no-install-recommends microsoft-edge-stable

#-- Install WebDriver -- matching version as Edge we just installed
RUN set -x; \
    EDGE_VERSION=$(dpkg-query --showformat='${Version}' --show microsoft-edge-stable | sed s/-1$//) && \
    WEBDRIVER=https://msedgedriver.azureedge.net/127.0.2651.107/edgedriver_linux64.zip && \
    echo "Edge version $EDGE_VERSION" && \
    echo "WebDriver $WEBDRIVER" && \
    wget $WEBDRIVER -O /tmp/webdriver.zip && \
    unzip /tmp/webdriver.zip msedgedriver -d /usr/local/bin/ && \
    rm -vf /tmp/webdriver.zip && \
    ls -l `which msedgedriver`

#-- https://learn.microsoft.com/en-us/microsoft-edge/webdriver-chromium/

[...]

Also easy to find more pedestrian guides, here's one https://linuxcapable.com/how-to-install-microsoft-edge-on-debian-linux/

... This is so cool, ⭐ https://github.com/microsoft/linux-package-repositories

Anyway, awesome tip, thanks again!

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