grafana/k6 · error

browser process shutdown unexpectedly before establishing a…

Error message

browser process shutdown unexpectedly before establishing a connection: %w

What it means

While parsing the browser's stderr for the DevTools WebSocket URL, the output stream closed (fs.ErrClosed) before any URL appeared — meaning the browser process exited before establishing a CDP connection. The wrapped error identifies the premature close.

Solutions

  1. Check browser stderr/logs for startup failure (bad flags, sandbox, missing libs)
  2. Remove incompatible launch arguments
  3. Test the binary manually with the same flags outside k6
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/browser_process.go:272 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/f5112c3139c20df6. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/browser_process.go:272

		if i := strings.Index(line, "] "); i > 0 {
			p.errs = append(p.errs, errors.New(line[i+2:]))
		}
	}

	return p.url == ""
}

func (p *devToolsURLParser) err() error {
	if p.url != "" {
		return io.EOF
	}
	if len(p.errs) > 0 {
		return p.errs[0]
	}

	err := p.sc.Err()
	if errors.Is(err, fs.ErrClosed) {
		return fmt.Errorf("browser process shutdown unexpectedly before establishing a connection: %w", err)
	}
	if err != nil {
		return err //nolint:wrapcheck
	}

	return nil
}

View on GitHub (pinned to 01ffac6f24)