Is there any possibility to collect API , AJAX requests and its information which are being triggered in browser while running k6 browser performance tests

We are looking for a possibility to access the requests which are being triggered during run of k6 browser performance test either through browser API or methods. i have tried below options already while running k6 browser performance test

Approach 1 : by using waitForEvent(event[, optionsOrPredicate])

As per documentation by k6 Currently this argument is disregarded, and waitForEvent will always wait for ‘close’ or ‘page’ events.
No more event tracking possible with this approach.

Approach 2 : using PerformanceObserver.

// Create a PerformanceObserver to monitor network requests 

const observer = new PerformanceObserver(logNetworkRequests); 

// Specify the entry types to observe (in this case, 'resource' entries for network requests) observer.observe({ entryTypes: ['resource'] });

observer.observe({ entryTypes: ['resource'] }); 
// Log the current network requests 
// Add an event listener for user interactions (e.g., click, keypress) 
document.addEventListener('click', handleUserInteraction);

This approach didn’t work because k6 doesn’t provide access to window object and Performance Observer is available in the window object

is there any other way through which i can collect all the network requests which are triggered during the browser performance test

As of my last knowledge update in September 2021, k6 primarily focused on HTTP request-level performance testing. It didn’t directly support capturing API, AJAX requests, or other browser-level interactions. It was designed for testing APIs and microservices.

If you need to capture API, AJAX requests, and browser-level interactions during performance testing, you might want to look into other tools like Selenium, Puppeteer, or Playwright. These tools are specifically designed for browser automation and can capture network requests made by a webpage.

If there have been any significant updates or additions to k6 after September 2021, I would not be aware of them. Please consult the official k6 documentation or community resources for the most up-to-date information.
Read more.

Hi @saurabh1993,

We don’t yet support listening for network requests from the k6-browser side. However, you can still write and run custom JavaScript code within a browser page. See: evaluate(pageFunction[, arg]).

Hope this helps.

PS: @onlinebillexpert, k6 has a browser module that enables users to test browser-level interactions. See: browser.


I don’t fully understand your intentions about collecting network requests, but if you want for example see, which URL-s were visited during the test (and you don’t want to use this information during test run), then you have some options:

  • You can use the csv or json output --out=csv or --out=json to get detailed metrics from every request, and you can process the data after the test run Real time (you can see the URLs n the csv or json output)
  • Or you can write a custom output extension in go and compile it into k6 with xk6 to process the detailed metrics during the test run Output Extensions
  • Or you can use the xk6-output-plugin extension, and write a plugin for it on any another programming language and process the detailed metrics during the test run
1 Like

Hi @bandorko we are not looking for those urls which user visted. We are looking to for individual network request time which browser is making while we are running K6 browser performance tests.
This will help us to find and pin point the bottlenecks in server calls


All the 3 options I mentioned contains all the network requests, not just the directly visited URLs.