Knowledgebase

How to do a browser recording

You can use the HAR converter to convert HAR files generated by e.g. Firefox or Chrome. This enables you to easily record user sessions for your site/app and then replay those sessions in a k6 load test.

Here are the basic steps you need to take to make a recording in some popular browsers:

  1. Open a new incognito window in Chrome (not really necessary, but using an incognito window means you won't be sending a lot of cookies etc that might have been saved by your browser)

  2. Open up Chrome developer tools (CMD+SHIFT+I on a Mac)

  3. Click the "Network" tab

  4. Click the "Preserve log" checkbox if you want to make a recording of several successive page loads

  5. Go to your site and start doing whatever you'd like your simulated load test users to be doing

  6. When done, right-click on the list of URLs in Chrome developer tools and choose "Save as HAR with content" - see screenshot below

    Chrome save to HAR

  7. Convert the HAR file using k6:
    k6 convert -O myscript.js myfile.har

  8. Run the resulting myscript.js script:
    k6 run myscript.js

  1. Open a new private window in Firefox (not really necessary, but using a private window means you won't be sending a lot of cookies etc that might have been saved by your browser)

  2. Open up Firefox developer tools (CMD+SHIFT+I on a Mac)

  3. Click the "Network" tab

  4. Click the "Preserve logs" checkbox if you want to make a recording of several successive page loads

  5. Go to your site and start doing whatever you'd like your simulated load test users to be doing

  6. When done, right-click on the list of URLs in Firefox developer tools and choose "Save all as HAR" - see screenshot below

    Chrome save to HAR

  7. Convert the HAR file using k6:
    k6 convert -O myscript.js myfile.har

  8. Run the resulting myscript.js script:
    k6 run myscript.js

Recommended is of course to review the script before running it. There may be dynamic data used on your site - CSRF tokens or whatnot - that will be hardcoded into the k6 script and which you may want to replace with dynamic data that k6 gets from the server you are testing.

See also: