I’m using k6 browser for browser-based load testing of our web application and need to capture all network requests made by the application during these tests.
We need to capture and analyze all network requests during our k6 browser tests to:
Monitor API usage and performance.
Validate that the application is making the correct network calls.
Collect metrics on request timings and payloads for analysis.
It seems all approaches have issues:
- Overriding window.fetch and XMLHttpRequest. Overriding native browser APIs can lead to instability and interfere with the application’s normal operation, causing crashes or unexpected behavior
- Lack of Network Interception Methods: Methods like page.on(‘request’) and page.route() used in Playwright/Puppeteer are not available in k6’s browser module.
- No CDP Access: The k6 browser module doesn’t expose Chrome DevTools Protocol (CDP) sessions, limiting our ability to intercept network traffic.
Is there a recommended way within k6 to capture all network requests during browser tests?
Are there any workarounds or planned features to enable network interception in k6’s browser module?
What would be the best approach to achieve our goal within the k6 framework?