Skip to main content
The k6 browser module brings browser automation and end-to-end web testing to k6 while supporting core k6 features. It adds browser-level APIs to interact with browsers and collect frontend performance metrics.

Overview

The browser module is built into k6 (not a separate extension) and provides:
  • Browser automation with Playwright-compatible APIs
  • Frontend performance metrics (Web Vitals)
  • Real browser interaction testing
  • Integration with protocol-level load testing
To use the browser module, you need:

Watch: Introduction to k6 browser

Use cases

The browser module helps you:

Frontend performance

Measure user experience with Web Vitals and page load metrics

Combined testing

Test frontend under protocol-level load to find real-world bottlenecks

Element validation

Verify all UI elements are interactive and loading correctly

User flows

Test complete user journeys across multiple pages
Browser-level testing helps answer questions like:
  • When my application receives thousands of simultaneous requests, what happens to the frontend?
  • How can I get metrics specific to browsers, like total page load time?
  • Are all my elements interactive on the frontend?
  • Are there loading spinners that take too long to disappear?

Quick start

1

Install k6

Download and install the latest k6 version.
2

Install a Chromium browser

Install Google Chrome, Microsoft Edge, or another Chromium-based browser.
3

Create a browser test

Generate a browser test template:
4

Run the test

Execute your browser test:

Example browser test

Here’s a simple browser test that navigates to a page and checks elements:

Browser metrics

The browser module automatically collects metrics:

Browser-specific metrics

Web Vitals

Example output:

Playwright-compatible APIs

The browser module uses Playwright-inspired APIs:

Combining browser and protocol tests

Test frontend performance under realistic protocol-level load:

Browser options

Configure browser behavior:

Debugging browser tests

Run in headed mode

See the browser window during test execution:

Take screenshots

Capture page state:

Slow down execution

Migrating from Playwright

If you have existing Playwright tests, migration is straightforward: Playwright:
k6 browser:
Key differences:
  • No need to launch/close browser (k6 manages this)
  • Use k6’s export default function instead of IIFE
  • Use import instead of require
  • k6 automatically handles concurrent browser instances

Best practices

Use headless mode

Run tests in headless mode for better performance in CI/CD

Set appropriate timeouts

Configure timeouts based on your application’s performance

Clean up resources

Always close pages in a finally block to prevent resource leaks

Limit browser VUs

Browser tests are resource-intensive; use fewer VUs than protocol tests

Next steps

Explore Extensions

Discover other k6 extensions

xk6-disruptor

Add chaos testing to your suite

Protocol Extensions

Test MQTT, Redis, and SQL

Full Browser API

Complete browser module reference