Netlify Plugin Chromium
🤖 Netlify Build Plugin for adding Chromium to Netlify CI/CD pipeline.
About
This is Netlify Build Plugin. It is meant to be used in projects connected to Netlify CI/CD pipeline. Netlify Build Plugins are currently opt-in BETA feature. Learn how to enable them for your project here.
This plugin hooks into installation stage of the build process and extends it with additional step which checks if Chromium is installed and installs Chromium binaries if needed. The latest suitable build of Chromium for your platform will be installed with the help of chromium npm package. Installation typically takes around 20-30 seconds.
⚠️ Important: By default, this plugin modifies value of environment variable CHROME_PATH
. Read more »
Usage
Installation
First, install this package from NPM as a dependency in your project:
npm install --save-dev netlify-plugin-chromium
(Alternatively, download its source code from GitHub.)
Then, add it to your Netlify configuration file:
plugins: - package: netlify-plugin-chromium
Configuration
Options
Name | Type | Description | Default value |
---|---|---|---|
packageManager |
npm | yarn |
Package manager to install Chromium with; npm or yarn . |
npm |
setChromePathInEnv |
boolean | If true, sets value of environment variable CHROME_PATH to location of local copy of Chromium binaries. This change is required by many tools relying on Chromium to be able to find it and launch it successfully (such as Lighthouse). |
true |
failBuildOnError |
boolean | If true and Chromium installation finished with failure, whole build will fail. Otherwise, only this plugin fails and the rest of the build proceeds as usual. | false |
Example
plugins: - package: netlify-plugin-chromium inputs: packageManager: yarn setChromePathInEnv: false failBuildOnError: true
Output
This plugin will generate output in your build logs similar to this:
10:50:12 PM: ┌────────────────────────────────────────────────────┐10:50:12 PM: │ 1. onPreBuild command from netlify-plugin-chromium │10:50:12 PM: └────────────────────────────────────────────────────┘10:50:12 PM: 10:50:12 PM: [NetlifyChromiumPlugin]: Installing Chromium with settings: {"packageManager":"npm","setChromePathInEnv":true,"failBuildOnError":false}10:50:12 PM: [NetlifyChromiumPlugin]: Chromium is not available, attempting to download10:50:27 PM: > chromium@2.1.2 postinstall /opt/build/repo/node_modules/chromium10:50:27 PM: > node install.js10:50:27 PM: Step 1. Retrieving Chromium latest revision number10:50:27 PM: Step 2. Downloading Chromium
Modification of environment variables
By default, this plugin sets value of environment variable CHROME_PATH
to location of local copy of Chromium binaries. This change is required by many tools relying on Chromium to be able to find it and launch it successfully (such as Lighthouse). However, you can opt out of this change by setting setChromePathInEnv
parameter to false
.
(In that case it is likely that you'd like to set this variable by yourself. Path to Chromium is exposed in build logs. Chromium is installed separately with each build, but typically it should be at the same location. You can take it from build logs, set it manually, disable setChromePathInEnv
parameter, re-run the build, and expect it to work properly.)
Usage examples
- coronavirus-tracker uses this plugin to automatically run Lighthouse CI tests for each build.
TODO
- write functional tests with
ChromeLauncher
(especiallygetInstallations
method)