Launching the k6 recorder extension automatically?

Hey folks, been searching but with no success, so asking here.

I have some UI automation that my team wants to convert to k6 UI performance tests. They’re written using Playwright - Cucumber - Typescript, which is not supported by k6, and I saw something online that said to use the k6 browser recorder to capture the automation steps during execution.

Problem is that I have to manually start the recorder after the browser is launched, let the automation perform the steps, then stop the recorder before the automation closes the browser, and trying to start the recorder causes the automation to prematurely abort.

Is there some magic sauce I can use in my existing automation to enable the recording in the extension in each of the tabs (four tabs get opened, and each does actions in a separate site that interact in the backends) so that the recorded automation gets automatically saved?

Thanks!
Mike

Hi!

As far as I’m aware, it’s not possible to automate extensions.

We have a utility cli called har-to-k6 which can convert a HAR-file to a k6 script (which is used under the hood when recording). What you might be able to do is launch chrome like this:

import { chromium } from "playwright"

const browser = await chromium.launch({
  headless: false,
  args: ["--auto-open-devtools-for-tabs"]
})

This should open a browser with the devtools open. Once the recording HAR finished (make sure that it won’t close the browser window) go to the networks tab and export everything as a HAR file.

Then you should be able to run it through the har-to-k6 CLI to generate a script.