{"record":{"id":"f5112c3139c20df6","repo":"grafana/k6","slug":"browser-process-shutdown-unexpectedly-before-estab","errorCode":null,"errorMessage":"browser process shutdown unexpectedly before establishing a connection: %w","messagePattern":"browser process shutdown unexpectedly before establishing a connection: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/js/modules/k6/browser/common/browser_process.go","lineNumber":272,"sourceCode":"\t\tif i := strings.Index(line, \"] \"); i > 0 {\n\t\t\tp.errs = append(p.errs, errors.New(line[i+2:]))\n\t\t}\n\t}\n\n\treturn p.url == \"\"\n}\n\nfunc (p *devToolsURLParser) err() error {\n\tif p.url != \"\" {\n\t\treturn io.EOF\n\t}\n\tif len(p.errs) > 0 {\n\t\treturn p.errs[0]\n\t}\n\n\terr := p.sc.Err()\n\tif errors.Is(err, fs.ErrClosed) {\n\t\treturn fmt.Errorf(\"browser process shutdown unexpectedly before establishing a connection: %w\", err)\n\t}\n\tif err != nil {\n\t\treturn err //nolint:wrapcheck\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":254,"sourceCodeEnd":280,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/browser_process.go#L254-L280","documentation":"The devToolsURLParser scans the browser's stderr for the DevTools websocket endpoint. If the pipe comes back fs.ErrClosed, the browser process exited before ever printing its ws endpoint, and k6 wraps that as an unexpected pre-connection shutdown. This is the classic 'browser died at launch' error.","triggerScenarios":"Chrome exits immediately on startup: missing shared libraries (libnss3/libatk on slim images), invalid flags passed via K6_BROWSER_ARGUMENTS, sandbox failure in root containers (no --no-sandbox), incompatible/very old Chromium build, or the user-data-dir being unwritable.","commonSituations":"Running headless Chromium on minimal CI images (alpine, debian-slim) without lib dependencies; passing K6_BROWSER_ARGUMENTS=\"--headless=new --bad-flag\"; running as root in Docker without --no-sandbox; disk-full temp directory for the user data dir.","solutions":["Run the same binary manually with the same arguments (add --headless --dump-dom about:blank) and read its stderr — it names the real problem.","On slim images, install Chromium runtime deps (libnss3, libatk-bridge2.0-0, libdrm, libxkbcommon, ...) or use a full image.","In root containers add --no-sandbox via K6_BROWSER_ARGUMENTS (or a non-root user).","Remove recently added custom K6_BROWSER_ARGUMENTS flags one by one to find the bad one.","Ensure TMPDIR/disk has space for the per-launch user data dir."],"exampleFix":"# before\n# slim CI image, chrome exits silently at launch\nk6 run test.js  # browser process shutdown unexpectedly...\n\n# after\napt-get install -y libnss3 libatk-bridge2.0-0 libdrm libxkbcommon libgbm1\nk6 run test.js","handlingStrategy":"validation","validationCode":"# CI pre-flight: launch the browser once with k6's flags and confirm it prints a DevTools endpoint\nCHROME=\"${K6_BROWSER_EXECUTABLE_PATH:-chromium}\"\ntimeout 10 \"$CHROME\" --headless --no-sandbox --disable-gpu --dump-dom about:blank >/dev/null 2>/tmp/chrome-smoke.err \\\n  || { echo 'browser fails to start:'; cat /tmp/chrome-smoke.err; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the browser binary manually with the same K6_BROWSER_ARGUMENTS whenever flags change.","Use images with Chromium's shared-library deps or install them explicitly.","Add --no-sandbox when running as root in containers; keep the user data dir on writable storage."],"tags":["browser","process","launch","dependencies","containers","ci"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}