grafana/k6 · error

initializing browser type

Error message

initializing browser type: %w

What it means

BrowserType.init failed inside ConnectOverCDP while preparing the browser context (logger setup, options parsing, or category filter). This wrap aggregates any of those init-step failures before the WebSocket connection to the remote browser is attempted.

Solutions

  1. Read the wrapped error to identify which init step failed
  2. Fix the corresponding K6_BROWSER_* env var or scenario option
  3. Retry once env configuration is corrected
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/chromium/browser_type.go:135 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at internal/js/modules/k6/browser/chromium/browser_type.go:135

//
// The passed context must be the context the caller wants to control both the
// connection and the browser lifetime; when it is canceled (iteration ends),
// the connection is torn down.
func (b *BrowserType) ConnectOverCDP(ctx context.Context, wsEndpoint string) (*common.Browser, error) {
	// Validate wsEndpoint up front so an empty or malformed value
	// fails fast with a clear error, instead of a confusing lower-level
	// connection error.
	if err := validateWSEndpoint(wsEndpoint); err != nil {
		return nil, err
	}

	// Parse browser options from the environment (K6_BROWSER_TIMEOUT,
	// K6_BROWSER_DEBUG, the log category filter, ...) like Connect does. Pass a
	// fixed chromium type instead of scenario options: connectOverCDP works
	// without a browser scenario, and Parse requires the type to be set.
	ctx, browserOpts, logger, err := b.init(ctx, true, map[string]any{"type": "chromium"})
	if err != nil {
		return nil, fmt.Errorf("initializing browser type: %w", err)
	}

	bp, err := b.connect(ctx, ctx, wsEndpoint, browserOpts, logger)
	if err != nil {
		err = &k6ext.UserFriendlyError{
			Err:     err,
			Timeout: browserOpts.Timeout,
		}
		return nil, fmt.Errorf("%w", err)
	}

	return bp, nil
}

// validateWSEndpoint returns an error if wsEndpoint is not a usable CDP
// WebSocket URL, catching common mistakes (an empty value, a non-ws scheme,
// a missing host, etc.) before we attempt to connect.
func validateWSEndpoint(wsEndpoint string) error {

View on GitHub (pinned to 8d06114777)