Title: Browser Automation via Chromium
Slug: browser-automation-via-chromium
Date: 2023-05-04 19:55:00
Author: Kartones
Lang: en
Tags: Tools, Testing, Automation
og_image:
Description: How to set up browser automation using Google browsers, emphasizing Chromium, which has advantages over Chrome, including the ability to access previous builds. Also covers the use of ChromeDriver and automation frameworks like WebDriverIO, as well setting up the Widevine DRM library and command-line switches.


Browser automation has advanced a lot, not only regarding the frameworks and tools but also in the most fundamental piece: the browser itself. Google Chrome is now very mature, has the biggest market share (as of mid'2023), and complies with all web standards, so it is an excellent starting point for automation projects.

In this post, I'll mention the most relevant pieces you need to set it up.

<br/>

Using Google's [Chromium](https://www.chromium.org/Home/) instead of the main Chrome has two main advantages: 

- Some of the Google-specific features are removed, and any Google APIs require API keys to function, so they will be disabled by default
- Unlike with Chrome, it is easy to get previous builds, so you're not forced to always test only with the latest version

But otherwise, it is the same browser.

There is a handy latest build link to download Chromium: [https://download-chromium.appspot.com](https://download-chromium.appspot.com)

Since June 2023, Google also publishes [**Chrome for Testing**](https://developer.chrome.com/blog/chrome-for-testing/), all builds way more accesible (including downloading JSON files with the URLs, handy for automation). The only caveat is that, same as the official Chromium ones, they come without the DRM flag (explanation in the next paragraph).

Be aware that those builds, under Linux, come **without** the [Widevine](https://en.wikipedia.org/wiki/Widevine) (DRM) compilation flag, so even if you follow the steps below, it won't work with protected content.

The [ungoogled-chromium-binaries GitHub project](https://github.com/clickot/ungoogled-chromium-binaries/) provides Linux binaries compiled **with** the DRM flag. From the releases page is easy to pick either the latest version or a specific one:

`https://github.com/clickot/ungoogled-chromium-binaries/releases/download/112.0.5615.165-1/ungoogled-chromium_112.0.5615.165-1.1_linux.tar.xz`

An alternative site that hosts binaries for all platforms compiled with the DRM flag is: [https://chromium.woolyss.com/](https://chromium.woolyss.com/)


[ChromeDriver](https://chromedriver.chromium.org/) is another critical piece, alongside an automation framework like [WebDriverIO](https://webdriver.io/). It is easy to automate fetching a certain version via their download URLs:

 `https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1109220/chromedriver_linux64.zip`


As mentioned before, Chromium might come without the DRM library, Widevine. You can fetch specific versions via URLs like the following:

`https://dl.google.com/widevine-cdm/4.10.2557.0-linux-x64.zip`

Following the instructions provided at the [chromium-widevine GitHub project](https://github.com/proprietary/chromium-widevine/) set it up, which consists of extracting the files in a certain subfolder structure inside Chromium's main folder.


Another URL you'll use a lot when setting up Chromium automation is [https://peter.sh/experiments/chromium-command-line-switches/](https://peter.sh/experiments/chromium-command-line-switches/), because it contains a complete list of the hundreds of command-line arguments/flags/switches. There is no official documentation, so this is really valuable.


For debugging errors thrown by the browser, you probably want to use the flags `--enable-logging=stderr --v=1`.



Suppose you plan to run automated browsers in a Linux environment without display (like a Docker container, or a CI instance installed without the X Server). In that case, you will probably want to use [XVFB](https://en.wikipedia.org/wiki/Xvfb) (and `xvfb-run`).


Finally, if you are really brave, and have some spare time, you can manually [download and compile Chromium](https://chromium.googlesource.com/chromium/src/+/main/docs/linux/build_instructions.md) from the source code, but it is time-consuming.


UPDATE #1: Added friend suggestion of another page containing binaries for all platforms (including Linux with DRM flag).

UPDATE #2: Added *Chrome for Testing* URL.