grafana/k6 · error
invalid WebSocket endpoint
Error message
invalid WebSocket endpoint %q: host is missing
What it means
The wsEndpoint URL parsed but contains no host component (e.g. 'ws:///path'). validateWSEndpoint requires a reachable host before connecting; the endpoint is echoed in the message.
Solutions
- Include host and port: ws://localhost:9222/devtools/browser/<id>
- Verify the browser is running and exposing its DevTools WebSocket
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/chromium/browser_type.go:170 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/7b40cfb6742ef9cd.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/chromium/browser_type.go:170
// a missing host, etc.) before we attempt to connect.
func validateWSEndpoint(wsEndpoint string) error {
if strings.TrimSpace(wsEndpoint) == "" {
return errors.New("WebSocket endpoint cannot be empty")
}
u, err := url.Parse(wsEndpoint)
if err != nil {
return fmt.Errorf("invalid WebSocket endpoint %q: %w", wsEndpoint, err)
}
if u.Scheme != "ws" && u.Scheme != "wss" {
return fmt.Errorf(
"invalid WebSocket endpoint %q: scheme must be ws or wss, got %q", wsEndpoint, u.Scheme,
)
}
if u.Hostname() == "" {
return fmt.Errorf("invalid WebSocket endpoint %q: host is missing", wsEndpoint)
}
return nil
}
// Connect attaches k6 browser to an existing browser instance.
//
// vuCtx is the context coming from the VU itself. The k6 vu/iteration controls
// its lifecycle.
//
// context.background() is used when connecting to an instance of chromium. The
// connection lifecycle should be handled by the k6 event system.
//
// The separation is important to allow for the iteration to end when k6 requires
// the iteration to end (e.g. during a SIGTERM) and unblocks k6 to then fire off
// the events which allows the connection to close.
func (b *BrowserType) Connect(ctx, vuCtx context.Context, wsEndpoint string) (*common.Browser, error) {
vuCtx, browserOpts, logger, err := b.init(vuCtx, true, k6ext.GetScenarioOpts(b.vu.Context(), b.vu))View on GitHub (pinned to 8d06114777)