{"record":{"id":"99ad0b30c7ae37e0","repo":"grafana/k6","slug":"browser-process-ended-unexpectedly","errorCode":null,"errorMessage":"browser process ended unexpectedly","messagePattern":"browser process ended unexpectedly","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/browser_process.go","lineNumber":225,"sourceCode":"// it. If the process ends abruptly, it will return the first error from stderr.\nfunc parseDevToolsURL(ctx context.Context, cmd command) (_ string, err error) {\n\tparser := &devToolsURLParser{\n\t\tsc: bufio.NewScanner(cmd.stderr),\n\t}\n\tdone := make(chan struct{})\n\tgo func() {\n\t\tfor parser.scan() {\n\t\t}\n\t\tclose(done)\n\t}()\n\tfor err == nil {\n\t\tselect {\n\t\tcase <-done:\n\t\t\terr = parser.err()\n\t\tcase <-ctx.Done():\n\t\t\terr = ContextErr(ctx)\n\t\tcase <-cmd.done:\n\t\t\terr = errors.New(\"browser process ended unexpectedly\")\n\t\t}\n\t}\n\tif parser.url != \"\" {\n\t\terr = nil\n\t}\n\n\treturn parser.url, err\n}\n\ntype devToolsURLParser struct {\n\tsc *bufio.Scanner\n\n\terrs []error\n\turl  string\n}\n\nfunc (p *devToolsURLParser) scan() bool {\n\tif !p.sc.Scan() {","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_process.go#L207-L243","documentation":"When launching a local browser, k6 starts the Chrome process, parses its stderr for the DevTools WebSocket URL, and watches the process. If the process's done channel fires before a URL was parsed, the browser died during startup — the parse result is discarded and 'browser process ended unexpectedly' is returned. It is the catch-all for Chrome crashing immediately on launch.","triggerScenarios":"Chrome exits at startup: missing shared libraries in a slim container (libnss3, libgbm, libatk...); running as root without --no-sandbox; incompatible flags passed via args/K6_BROWSER_ARGUMENTS; wrong-architecture or broken binary; the data dir being unwritable.","commonSituations":"Minimal Docker images without chromium dependencies; CI running as root; custom Chrome flags copied from Playwright configs; snap-packaged Chromium on Ubuntu; disk-full or read-only profiles.","solutions":["Reproduce outside k6 to see the real stderr: run the exact binary with your flags, e.g. google-chrome --headless=new --no-sandbox --dump-dom about:blank — install whatever libraries it complains about","When running as root (containers/CI), pass --no-sandbox: K6_BROWSER_ARGS='--no-sandbox' or args in browser options","Verify the executable is a genuine Chrome/Chromium binary for this architecture (file /usr/bin/chromium)","Or skip local launch entirely: K6_BROWSER_WS_ENDPOINT=ws://host:9222/... against an already-running browser"],"exampleFix":"# before (root container, missing deps)\nRUN apk add --no-cache k6\n\n# after\nRUN apk add --no-cache k6 chromium nss freetype freetype-dev harfbuzz ca-certificates ttf-liberation\nENV K6_BROWSER_EXECUTABLE_PATH=/usr/bin/chromium-browser \\\n    K6_BROWSER_ARGS=\"--no-sandbox\"","handlingStrategy":"validation","validationCode":"#!/bin/sh\n# Validate the browser launches with the same flags k6 will use before running tests\nBIN=\"${K6_BROWSER_EXECUTABLE_PATH:-$(command -v google-chrome || command -v chromium)}\"\n[ -n \"$BIN\" ] || { echo 'no browser binary found' >&2; exit 1; }\nexec \"$BIN\" --headless=new --no-sandbox --user-data-dir=/tmp/k6-preflight --dump-dom about:blank >/dev/null","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In root containers always pass --no-sandbox via K6_BROWSER_ARGS or the args browser option","Use a chromium-bundled image and pin it; install the standard dependency set (nss, gbm, atk, cups, gtk)","Do not pass flags that disable the DevTools endpoint or user-data-dir; k6 needs the WebSocket URL from stderr","For locked-down runners, switch to K6_BROWSER_WS_ENDPOINT against an external Chrome service"],"tags":["browser","chrome","process","startup","docker","ci","dependencies"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}