The countdown is on: Register today + save your seatLearn how to leverage new AI features and observability tools, attend technical deep dives. & leave with tips for growing your observability strategy. Seats are limited and in high demand, register now!
📢 Registration + agenda now live
Explore the latest Grafana Cloud and AI solutions, learn tips & tricks from demos and hands-on workshops, and get actionable advice to advance your observability strategy. Register now and get 50% off - limited tickets available (while they last!).
The method adds a route that allows modifying network requests matching the provided url. The handler is a function taking a
Route input that provides functions to
continue,
fulfill or
abort the request. Once routing is enabled, every request matching the url pattern will stall unless one of these functions is called.
When several routes match the given pattern, only the last registered route handler will run, and all others will be skipped.
Handler function executed when routing the request.
Returns
Type
Description
Promise<void>
A Promise that fulfills when the route is added to the page.
Example
JavaScript
import{ browser }from'k6/browser';exportconst options ={scenarios:{browser:{executor:'shared-iterations',options:{browser:{type:'chromium',},},},},};exportdefaultasyncfunction(){const page =await browser.newPage();// Abort all images requestsawait page.route(/(\.png$)|(\.jpg$)/,asyncfunction(route){await route.abort();});// Fulfill request with the following response which// changes the quotes displayed on the pageawait page.route(/.*\/quotes$/,asyncfunction(route){await route.fulfill({body:JSON.stringify({quotes:['"We ❤️ pizza" - k6 team'],}),});});// Change the pizza request when the button is clickedawait page.route(/.*\/pizza$/,asyncfunction(route){await route.continue({headers:{...route.request().headers(),foo:'bar',},method:'POST',postData:JSON.stringify({maxCaloriesPerSlice:500,mustBeVegetarian:true,excludedIngredients:['Pineapple'],excludedTools:['Knife','Scissors'],maxNumberOfToppings:1,minNumberOfToppings:1,customName:'Classic Pizza',}),});});await page.goto('https://quickpizza.grafana.com/');await page.getByRole('button',{name:'Pizza, Please!'}).click();await page.close();}