grafana/k6 · error

connecting to browser

Error message

connecting to browser: %w

What it means

BrowserType.link failed to establish the CDP WebSocket connection to the browser at wsURL, returning a nil browser process. The wrapped error carries the underlying dial/WebSocket handshake failure; later, Connect wraps it in a UserFriendlyError with timeout context.

Solutions

  1. Verify the browser/CDP endpoint is up and reachable (network, firewall, correct port)
  2. Increase K6_BROWSER_TIMEOUT if the handshake is slow
  3. For remote runs check K6_INSTANCE_WS_URL / cloud connectivity; retry after fixing the endpoint
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/chromium/browser_type.go:210 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/c068f20e1cc61f26. Report an issue: GitHub.

Appendix: source

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

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

	return bp, nil
}

func (b *BrowserType) connect(
	ctx, vuCtx context.Context, wsURL string, opts *common.BrowserOptions, logger *log.Logger,
) (*common.Browser, error) {
	browserProc, err := b.link(ctx, wsURL, logger)
	if browserProc == nil {
		return nil, fmt.Errorf("connecting to browser: %w", err)
	}

	// If this context is cancelled we'll initiate an extension wide
	// cancellation and shutdown.
	browserCtx, browserCtxCancel := context.WithCancel(vuCtx)
	b.Ctx = browserCtx
	browser, err := common.NewBrowser(
		ctx, browserCtx, browserCtxCancel, browserProc, opts, logger,
	)
	if err != nil {
		return nil, fmt.Errorf("connecting to browser: %w", err)
	}

	return browser, nil
}

func (b *BrowserType) link(
	ctx context.Context,

View on GitHub (pinned to 8d06114777)