Browser options
To enable browser testing, add the browser configuration within the options property of the
Scenario options.
export const options = {
scenarios: {
foo: {
executor: 'shared-iterations',
options: {
browser: {
type: 'chromium',
},
},
},
},
};Script options
Environment variable options
You can customize the behavior of the browser module by passing environment variables.
Note
Customizing browser options via environment variables is unsupported when running browser tests in Grafana Cloud k6.
The following command passes the browser options as environment variables to launch a headful browser with custom arguments.
K6_BROWSER_HEADLESS=false K6_BROWSER_ARGS='show-property-changed-rects' k6 run script.js# WARNING!
# The grafana/k6:master-with-browser image launches a Chrome browser by setting the
# 'no-sandbox' argument. Only use it with trustworthy websites.
#
# As an alternative, you can use a Docker SECCOMP profile instead, and overwrite the
# Chrome arguments to not use 'no-sandbox' such as:
# docker container run --rm -i -e K6_BROWSER_ARGS='' --security-opt seccomp=$(pwd)/chrome.json grafana/k6:master-with-browser run - <script.js
#
# You can find an example of a hardened SECCOMP profile in:
# https://raw.githubusercontent.com/jfrazelle/dotfiles/master/etc/docker/seccomp/chrome.json.
docker run --rm -i -e K6_BROWSER_HEADLESS=false -e K6_BROWSER_ARGS='show-property-changed-rects' grafana/k6:master-with-browser run - <script.jsset "K6_BROWSER_HEADLESS=false" && set "K6_BROWSER_ARGS='show-property-changed-rects' " && k6 run script.js$env:K6_BROWSER_HEADLESS="false" ; $env:K6_BROWSER_ARGS='show-property-changed-rects' ; k6 run script.jsBrowser arguments
The following table highlights commonly useful arguments you can pass via the K6_BROWSER_ARGS environment variable. Most tests run without extra arguments, because the browser module already uses sensible defaults. Set these extra arguments only when you need to debug or adapt to your environment. For a complete list, refer to Chromium command line switches.
Note
Arguments should not start with
--when passing them toK6_BROWSER_ARGS.
For example, pass the following arguments to the K6_BROWSER_ARGS environment variable to ignore TLS certificate errors and route browser traffic through a proxy when running a browser test:
K6_BROWSER_ARGS='ignore-certificate-errors,proxy-server=127.0.0.1:8080' k6 run script.jsdocker run --rm -i -e K6_BROWSER_ARGS='ignore-certificate-errors,proxy-server=127.0.0.1:8080' grafana/k6:master-with-browser run - <script.jsset "K6_BROWSER_ARGS='ignore-certificate-errors,proxy-server=127.0.0.1:8080'" && k6 run script.js$env:K6_BROWSER_ARGS='ignore-certificate-errors,proxy-server=127.0.0.1:8080' ; k6 run script.jsDefault arguments
List of default arguments included when launching the browser process. You can pass one or more of the arguments to the K6_BROWSER_IGNORE_DEFAULT_ARGS environment variable when starting a test for the ones you want to ignore.
Note
The starting ‘–’ have been omitted from the argument names in these lists.
Additionally, the following arguments are set in headless mode (when K6_BROWSER_HEADLESS is true, which is the default option):