Retrieving a Cookie via k6/browser in the setup function to share it with further later running scenarios

I need to retrieve a cookie at the beginning of my test runs using k6/browser (for example, by logging in via browser automation), and then use this cookie for my subsequent HTTP-based performance testing scenarios. However, I am facing a problem:

  • If I use k6/browser in the setup() function to retrieve the cookie, the documentation says I should set the browser configuration at the top level of the options block, which I have done. But I still encounter errors about the browser not being found in the registry.
  • If I define a dedicated scenario for the browser-based login and run it first to retrieve the cookie, I cannot share the retrieved cookie with the other scenarios, because k6 does not allow sharing mutable data between VUs or scenarios.

How can I solve this problem? Is there a recommended way to retrieve a cookie with k6/browser and then use it in subsequent HTTP protocol-based scenarios for performance testing?