XK6 Browser gives an error: building browser on IterStart: launching browser: Running as root without --no-sandbox is not supported

Hi team,

I am using a mac M2 and I am trying to run the following Dockerfile from your Github repository.

FROM golang:1.19-bullseye as builder

RUN go install -trimpath go.k6.io/xk6/cmd/xk6@latest

RUN  xk6 build --output "/tmp/k6" --with github.com/grafana/xk6-browser

FROM debian:bullseye

RUN apt-get update && \
    apt-get install -y chromium

COPY --from=builder /tmp/k6 /usr/bin/k6

ENV XK6_HEADLESS=true

ENTRYPOINT ["k6"]

This is the test from the documentation on the K6 page.

import { browser } from "k6/experimental/browser";

export const options = {
    scenarios: {
        ui: {
            executor: "shared-iterations",
            options: {
                browser: {
                    type: "chromium"
                }
            }
        }
    },
    thresholds: {
        checks: ["rate==1.0"]
    }
};

export default async function () {
    const page = browser.newPage();

    try {
        await page.goto("https://test.k6.io/");
        page.screenshot({ path: "screenshot.png" });
    } finally {
        page.close();
    }
}

It gives me the following error

time="2023-08-15T14:54:02Z" level=error msg="process with PID 15 unexpectedly ended: exit status 1" category=browser elapsed="0 ms" source=browser

   ✓ checks...............: 0.00% ✓ 0        ✗ 0
     data_received........: 0 B   0 B/s
     data_sent............: 0 B   0 B/s
     iteration_duration...: avg=65.91µs min=65.91µs med=65.91µs max=65.91µs p(90)=65.91µs p(95)=65.91µs
     iterations...........: 1     6.163866/s


running (00m00.2s), 0/1 VUs, 0 complete and 1 interrupted iterations
ui   ✗ [ 100% ] 1 VUs  00m00.2s/10m0s  1/1 shared iters
time="2023-08-15T14:54:03Z" level=error msg="error building browser on IterStart: launching browser: Running as root without --no-sandbox is not supported. See https://crbug.com/638180. at file:///app/k6/tests/test.js:19:15(0)"

I tried to run it with the flag no sandbox, but this still does not work for me. Any idea what I am doing wrong?

const page = browser.newPage({headless: true, args:['--no-sandbox']});

Thanks,
Rody

Hi @rodyb

When running docker, can you try adding the environment variable K6_BROWSER_ARGS?

docker run --rm -i -e K6_BROWSER_ARGS='no-sandbox' <your-image> run - <test.js 

I think the behavior has changed with the breaking changes in v0.46.0. Before you could use args:['no-sandbox'] (without the --).

I hope this helps :bowing_woman:

Cheers!

2 Likes

@eyeveebee that works thank you!

1 Like