k6/browser adds requestfinished and requestfailed event handlers
Introduced 2026-02-10 · score 0.93
HOW TO USE IT
When debugging a k6 browser test, register `requestfailed` and `requestfinished` listeners on the page before navigation to observe failed and completed network requests.
import { browser } from 'k6/browser';
export const options = {
scenarios: {
ui: {
executor: 'shared-iterations',
options: { browser: { type: 'chromium' } },
},
},
};
export default async function () {
const page = await browser.newPage();
page.on('requestfailed', (request) => console.log(`Request failed: ${request.url()}`));
page.on('requestfinished', (request) => console.log(`Request finished: ${request.url()}`));
await page.goto('<URL>');
await page.close();
}WHY THIS HELPS
Monitor successful and failed network requests while debugging a k6 browser test.
REQUIREMENTS AND LIMITATIONS
- Version: v1.6.0
- event (required): Event name: `requestfailed` for requests that fail to reach the server; `requestfinished` for requests that successfully complete.
- handler (required): Callback invoked when the event is emitted; receives the corresponding Request object.
- request.url(): Returns the request URL; usable in the event handler for logging.
- Prerequisite: Use a current k6 version to work with the browser module.
- `requestfailed` fires for request failures such as network errors or aborts; `requestfinished` fires when a request completes successfully.
FIRST-PARTY EVIDENCE
- https://github.com/grafana/k6/releases/tag/v1.6.0
- https://grafana.com/docs/k6/latest/javascript-api/k6-browser/page/on/
- https://grafana.com/docs/k6/latest/javascript-api/k6-browser/request/
- https://grafana.com/docs/k6/latest/javascript-api/k6-browser/
Check the installed version and the source before using it. Entry JSON