Browser Automation via Chromium

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.

Using Google's Chromium 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:

Since June 2023, Google also publishes 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 (DRM) compilation flag, so even if you follow the steps below, it won't work with protected content.

The ungoogled-chromium-binaries GitHub project provides Linux binaries compiled with the DRM flag. From the releases page is easy to pick either the latest version or a specific one:

An alternative site that hosts binaries for all platforms compiled with the DRM flag is:

ChromeDriver is another critical piece, alongside an automation framework like WebDriverIO. It is easy to automate fetching a certain version via their download URLs:

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

Following the instructions provided at the chromium-widevine GitHub project 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, 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 (and xvfb-run).

Finally, if you are really brave, and have some spare time, you can manually download and compile Chromium 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.

Tags: Tools

Browser Automation via Chromium published @ . Author: