Skip to content
Owais Khan Software Reviews

HAR to k6 Converter

Open a HAR file recorded in your browser’s DevTools and get a k6 load test script — with static assets and trackers filtered out, redirects and cookies handled the way k6 handles them, and tokens replaced by environment variables.

Everything runs locally: your HAR file never leaves your browser.

Convert a HAR file to a k6 script

Request types
Domains
Script

Kept 4 of 11 requests. Skipped: 4 static assets, 1 analytics and trackers, 1 CORS preflights, 1 redirects k6 follows itself.

What happened to the example

The recording has eleven requests and the script sends four. The stylesheet, script, image and font are static assets; the Google Analytics hit is a tracker; the OPTIONS request is a CORS preflight the browser sent on its own; and /account/ is the second hop of a 302 that k6 will follow by itself — so the check on /account expects the final 200, not the 302. The session cookie and HTTP/2 :authority header are gone, the bearer token became __ENV.AUTH_TOKEN, the password became __ENV.PASSWORD, and the 2.6-second pause while the login form was filled in is kept as sleep(2.6).

Convert a HAR file to a k6 script: the steps

To convert a HAR file to a k6 script, record the journey in DevTools with “Preserve log” on, export it as HAR (with sensitive data, if the flow needs a login), and open it here. Untick domains you do not own, check the script, then run it with the environment variables listed on its first line: k6 run -e AUTH_TOKEN=… -e PASSWORD=… script.js. Start with 1 VU to confirm every check passes before raising the load.

A Grafana har-to-k6 alternative that runs in the browser

If you are looking for a Grafana har-to-k6 alternative because you cannot install Node.js or Docker on the machine you are working on, this runs in any browser tab, works offline once loaded, and keeps the recording on your machine. The output is a plain k6 script with no dependencies beyond k6 itself.

Generate a k6 script from HAR, then make it realistic

A script generated from a HAR replays one user’s exact session. To generate a k6 script from HAR that behaves like many users, replace the values that should differ per user — search terms, product IDs, IDs returned by an earlier response — with data from a SharedArray or values read from the previous response, and use scenarios in options to shape the load over time.

Frequently asked questions

Is my HAR file uploaded to a server?
No. The conversion runs entirely as a small script inside this page; your HAR never leaves your browser, and there is no upload, no API call and no analytics here. That matters more than usual for HAR files, which contain every cookie, token and form field of the session you recorded. It is enforced rather than promised: this site’s test suite scans the shipped HTML for every browser API capable of sending data off the page and fails the build if it finds one.
How is this different from Grafana’s har-to-k6 command-line tool?
Grafana publishes har-to-k6 as an npm package you run with Node.js or Docker. This does the same job without installing anything, and adds the clean-up a raw recording needs before it is a useful load test: request-type and domain filters, redirect handling, credential redaction and load options you can see and change before you download the script.
How do I strip static assets (images, CSS, fonts) from the generated k6 script?
They are left out by default. Images, stylesheets, JavaScript, fonts and media are usually served by a CDN and cached by real browsers, so replaying them measures the CDN rather than your application. Tick a type under "Request types" to put it back. Analytics and ad domains are unticked in the domain list for the same reason, and any other domain can be unticked there.
How are authentication headers and cookies handled?
Recorded Cookie headers are dropped: they belong to one browser session, and k6 keeps its own cookie jar for each virtual user, filled from the Set-Cookie headers your server sends — so a login request in the script logs each VU in. Authorization headers keep their scheme and take the token from an environment variable, for example "Bearer " + __ENV.AUTH_TOKEN; API-key headers and password or token fields in JSON and form bodies are replaced the same way. The first line of the script lists every variable to pass with k6 run -e.
Why does the script have fewer requests than my HAR file?
The line under the script counts every request that was left out and why. Besides static assets and trackers, CORS preflight OPTIONS requests are dropped because the browser sends them automatically and k6 does not need them; the second request of a redirect is dropped because k6 follows redirects itself, which would otherwise double it; and requests that failed or were blocked in the browser, data: URLs and WebSockets are skipped.
How do I export a HAR file from Chrome?
Open DevTools, go to the Network tab, tick "Preserve log", and do what you want to load-test. Then click the download arrow ("Export HAR") in the Network toolbar. Chrome strips cookies and Authorization headers from that export unless you choose the variant that includes sensitive data, which you need if the script should replay an authenticated session. Firefox and Safari have the same export in their network panels.