{"record":{"id":"4c95cc1b7c9baae8","repo":"grafana/k6","slug":"finding-browser-executable-w","errorCode":null,"errorMessage":"finding browser executable: %w","messagePattern":"finding browser executable: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/chromium/browser_type.go","lineNumber":287,"sourceCode":"}\n\nfunc (b *BrowserType) launch(\n\tctx, vuCtx context.Context, opts *common.BrowserOptions, logger *log.Logger,\n) (_ *common.Browser, pid int, _ error) {\n\tflags, err := prepareFlags(opts, &(b.vu.State()).Options)\n\tif err != nil {\n\t\treturn nil, 0, fmt.Errorf(\"%w\", err)\n\t}\n\n\tdataDir := &storage.Dir{}\n\tif err := dataDir.Make(b.tmpdir(), flags[\"user-data-dir\"]); err != nil {\n\t\treturn nil, 0, fmt.Errorf(\"%w\", err)\n\t}\n\tflags[\"user-data-dir\"] = dataDir.Dir\n\n\tpath, err := executablePath(opts.ExecutablePath, b.envLookupper, exec.LookPath)\n\tif err != nil {\n\t\treturn nil, 0, fmt.Errorf(\"finding browser executable: %w\", err)\n\t}\n\n\tbrowserProc, err := b.allocate(ctx, path, flags, dataDir, logger)\n\tif browserProc == nil {\n\t\treturn nil, 0, fmt.Errorf(\"launching browser: %w\", err)\n\t}\n\n\t// If this context is cancelled we'll initiate an extension wide\n\t// cancellation and shutdown.\n\tbrowserCtx, browserCtxCancel := context.WithCancel(vuCtx)\n\tb.Ctx = browserCtx\n\tbrowser, err := common.NewBrowser(ctx, browserCtx, browserCtxCancel,\n\t\tbrowserProc, opts, logger)\n\tif err != nil {\n\t\treturn nil, 0, fmt.Errorf(\"launching browser: %w\", err)\n\t}\n\n\treturn browser, browserProc.Pid(), nil","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/chromium/browser_type.go#L269-L305","documentation":"Returned by BrowserType.launch when executablePath() cannot resolve a Chrome/Chromium binary. It wraps either ErrChromeNotFoundAtPath (an explicit executablePath was given but exec.LookPath failed) or ErrChromeNotInstalled (none of the well-known names — headless_shell, chromium, google-chrome, chrome.exe, the macOS app paths, USERPROFILE fallback — resolved). Launch aborts before any process is spawned.","triggerScenarios":"chromium.launch() on a host with no Chrome/Chromium installed; executablePath option pointing to a wrong/nonexistent/relative path or a file without execute permission; minimal Docker images (alpine/distroless/slim) with no browser package; PATH not including the Chrome directory.","commonSituations":"Running k6 in a slim CI container without installing Chromium; pointing K6_BROWSER_EXECUTABLE_PATH at a path inside a different container; SELinux/AppArmor denying execution; the binary exists but is not on PATH and no explicit path was set.","solutions":["Install Chrome or Chromium (e.g. apt-get install -y chromium or the google-chrome-stable package), or use the k6 browser docker image which ships headless_shell","Set an explicit executable path: options.executablePath = '/usr/bin/chromium' (or export K6_BROWSER_EXECUTABLE_PATH=/usr/bin/google-chrome) and verify it exists with ls","Ensure the file is executable (chmod +x) and the path is absolute when launched from another working directory","If using headless_shell from the k6 image, confirm it is on PATH (it is by default in grafana/k6 images with browser support)"],"exampleFix":"# before (no chrome in container)\nk6 run browser_test.js\n\n# after\n## Dockerfile\nFROM grafana/k6:0.5x-with-browser\n# headless_shell is already included and on PATH\n\n## or in the script\nconst browser = chromium.launch({ executablePath: '/usr/bin/google-chrome-stable' });","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const browser = chromium.launch({ executablePath: __ENV.CHROME_PATH });\n} catch (e) {\n  const m = String(e.message);\n  if (m.includes('finding browser executable')) {\n    console.error('No Chrome/Chromium found. Install one or set K6_BROWSER_EXECUTABLE_PATH.', m);\n  }\n  throw e;\n}","preventionTips":["Bake Chrome/headless_shell into the CI image (use the grafana/k6 browser image)","Set K6_BROWSER_EXECUTABLE_PATH explicitly in containers instead of relying on PATH","Add a CI step that runs the resolved binary with --version before the test suite"],"tags":["launch","environment","executable","docker","configuration"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}