K6 browser test in docker container cannot access website

I’ve created a dockerfile to run my k6 browser test script in. The script should perform simple browser testing functions, like going to a login page, entering credentials, and hitting “login”, and it works as expected if I run it outside the docker container. However, when I run it inside the docker container, it errors when it tries to go to the login page:

ERRO[0002] error on evaluating window.k6SpanId: evaluating JS in global context: context canceled  category="FrameSession:onFrameNavigated" elapsed="0 ms" source=browser
ERRO[0002] Uncaught (in promise) TypeError: Cannot read property 'headers' of undefined or null
running at file:///home/username/browserTest.js:25:16(16)  executor=shared-iterations scenario=ui

I believe this might be because the login page it is trying to access is only available on the company network. My computer uses a VPN to connect to the company network, but perhaps specifically the chromium browser in the docker container is somehow not using the VPN? However, if I run a curl command to the login page inside the docker container, that works fine.

Notes:

  • I am not using the official k6 browser docker image, since I wanted to use a company image as my base image.
  • I can run the sample browser test script within my docker container and everything goes as expected.

Hi,

the chromium browser in the docker container is somehow not using the VPN

This might be the case. You might try these options by passing them to the browser module’s K6_BROWSER_ARGS environment variable (as explained in this other answer), but I’m not sure whether they’ll help Chromium connect to the private servers. It’s worth giving it a shot.