grafana/k6 · error
invalid WebSocket endpoint
Error message
invalid WebSocket endpoint %q: %w
What it means
The wsEndpoint string passed to chromium.connectOverCDP() is not a parseable URL. net/url.Parse failed on the raw string, so it is echoed verbatim; typical causes are stray characters, spaces, or a missing scheme delimiter.
Solutions
- Use a well-formed CDP WebSocket URL: ws://host:port/devtools/browser/<id>
- Verify the endpoint with a curl of http://host:port/json/version
- Trim whitespace and copy the URL exactly from Chrome's output
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/chromium/browser_type.go:160 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/a4d3aa549235d823.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/chromium/browser_type.go:160
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 {
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 controlsView on GitHub (pinned to 8d06114777)