grafana / k6

A modern load testing tool, using Go and JavaScript - https://k6.io
GNU Affero General Public License v3.0
26.1k stars 1.27k forks source link

Add Support for `page.on('request')`, `page.route()`, and CDP Access in k6 Browser Module #4020

Open aupadhyay-coursera opened 4 weeks ago

aupadhyay-coursera commented 4 weeks ago

Feature Description

Feature Request: Add Support for page.on('request'), page.route(), and CDP Access in k6 Browser Module

Description: There is a need for enhanced functionality in the k6 browser module. Specifically, methods like page.on('request') and page.route() used in Playwright/Puppeteer are not available. Additionally, the k6 browser module doesn’t expose Chrome DevTools Protocol (CDP) sessions, limiting our ability to intercept network traffic.

Proposed Features:

  1. Add Support for page.on('request'):

    • Enable event listeners for network requests similar to Playwright/Puppeteer.
    • Example use case: Logging or manipulating request/response headers.
  2. Add Support for page.route():

    • Enable request interception and the ability to mock responses or alter requests.
    • Example use case: Testing application behavior under different network conditions or simulating specific API responses.
  3. Expose CDP Sessions:

    • Provide access to Chrome DevTools Protocol (CDP) sessions.
    • Example use case: Intercepting network traffic, gathering performance metrics, or accessing detailed browser logs.

Use Cases:

  1. Enhanced Network Interception: Intercept network requests and modify them on the fly during load testing, enabling more detailed and specific test scenarios.
  2. Mocking and Simulating Network Conditions: Mock specific API responses or simulate network issues to test the resilience of applications.
  3. Gathering Detailed Metrics: Access performance metrics and browser logs via CDP to gain deeper insights into application performance under load.

Adding these features would align k6's capabilities more closely with existing browser automation tools like Playwright and Puppeteer, providing more comprehensive testing abilities.

Thank you for considering this request.

Suggested Solution (optional)

No response

Already existing or connected issues / PRs (optional)

No response

ankur22 commented 3 weeks ago

@aupadhyay-coursera thanks for opening an issue for these three feature requests that you've mentioned. They all have good use cases and ones which we would like to work on. We can't say when we will get to them but we will keep this issue open until we have a better idea of what the next steps are for this. I am working with the team to get a better answer.