Error building browser on IterStart: launching browser: browser process shutdown unexpectedly before establishing a connection: read |0: file already closed

I get the process shutdown unexpected error only when I run the below script in Alpine container with the latest k6 version (0.46.0) everything works as expected on mac. Do you have a sample dockerfile based on alpine image that is working?

// Frontend performance test simulating user interactions in a browser context
export async function frontendPerformanceTest() {
const page = browser.newPage();
try {
// Navigate to the login page
await page.goto(LOGIN_PAGE);

// Fill in the login form
page.locator('input[name="ctl00$Content$Login1$UserName"]').type('BroadL');
page.locator('input[name="ctl00$Content$Login1$Password"]').type('password');
const submitButton = page.locator('input[type="submit"]');

// Submit the form and wait for navigation
await Promise.all([page.waitForNavigation(), submitButton.click()]);

// Check the title of the resulting page
check(page, {
  'titleCheck': p => p.title() == 'Dr. 1101 Broad - 459032965 - ServiceB',
});

} catch (error) {
console.error(“Error in frontendPerformanceTest:”, error.message);
} finally {
// Close the browser context
page.close();
}
}

Here is the docker file i am using

FROM golang:alpine3.17 as builder

ENV CGO_ENABLED 0
RUN go install go.k6.io/xk6/cmd/xk6@latest

RUN xk6 build v0.46.0
–with github.com/grafana/xk6-sql@v0.2.1
–output /tmp/k6

FROM alpine:3.18

WORKDIR /app

ADD . .

USER root

RUN apk update &&
apk --no-cache add gnupg &&
apk --no-cache add chromium

RUN npm ci

USER ${SERVICE_USER}

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

Hi @pviswanathan , welcome to the forum :wave:

We have a dedicated k6 docker image (grafana/k6:master-with-browser) that already contains a browser. You can see the definition here.

Thanks Daniel. It works now

Hi @Daniel.J ,

Just curious to understand the difference between chromium vs chromium-swiftshader. Why would one use chromium-swiftshader?

chromium-swiftshader is the version available in alpine linux. You can read more about it here.

1 Like