How to add a custom user agent in k6 studio generated script where the script is not editable?

I am using k6 studio to record the steps but in that I want to put a custom user agent as cloudflare blocks the user agent I am using. So I have asked my dev team to whitelist the custom user agent I have created but now I am not finding a way to insert that user agent in to the script as the script in K6 studio is not editable. Please let me know how to do it.

Hi @ashutoshlashiyal,

You can add custom headers to your requests by adding a Custom Code rule in your generator.

  • Open your generator
  • Click Add rule > Custom code
  • Select “Before matched requests”
  • Add your custom header to the params.headers array

Example:

params.headers['User-Agent'] = 'test/123'

You can optionally filter specific URLs as well.

1 Like

Hi Cristian,

Thanks for your reply. I have not yet tried your solution. I will try this out once and hopefully this works. I will get back to you with the results when I try this out. Thanks