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:
- Latest k6 version
- A Chromium-based browser (such as Google Chrome) installed on your machine
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
- 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
Install k6
Download and install the latest k6 version.
Install a Chromium browser
Install Google Chrome, Microsoft Edge, or another Chromium-based browser.
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
| Metric | Description |
|---|---|
browser_data_received | Data received by the browser |
browser_data_sent | Data sent by the browser |
browser_http_req_duration | Time for browser HTTP requests |
browser_http_req_failed | Rate of failed browser HTTP requests |
Web Vitals
| Metric | Description |
|---|---|
browser_web_vital_cls | Cumulative Layout Shift |
browser_web_vital_fcp | First Contentful Paint |
browser_web_vital_fid | First Input Delay |
browser_web_vital_inp | Interaction to Next Paint |
browser_web_vital_lcp | Largest Contentful Paint |
browser_web_vital_ttfb | Time to First Byte |
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:- No need to launch/close browser (k6 manages this)
- Use k6’s
export default functioninstead of IIFE - Use
importinstead ofrequire - 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 leaksLimit 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