{"record":{"id":"83e5ca327c363cfa","repo":"grafana/k6","slug":"websocket-requires-a-url","errorCode":null,"errorMessage":"WebSocket requires a url","messagePattern":"WebSocket requires a url","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/websockets/websockets.go","lineNumber":163,"sourceCode":"\t\twriteQueueCh:    make(chan message),\n\t\teventListeners:  newEventListeners(),\n\t\tobj:             rt.NewObject(),\n\t\ttagsAndMeta:     params.tagsAndMeta,\n\t\tsendPings:       ping{timestamps: make(map[string]time.Time)},\n\t\tbinaryType:      blobBinaryType,\n\t}\n\n\t// Maybe have this after the goroutine below ?!?\n\tdefineWebsocket(rt, w)\n\n\tgo w.establishConnection(params)\n\treturn w.obj\n}\n\n// parseURL parses the url from the first constructor calls argument or returns an error\nfunc parseURL(urlValue sobek.Value) (*url.URL, error) {\n\tif common.IsNullish(urlValue) {\n\t\treturn nil, errors.New(\"WebSocket requires a url\")\n\t}\n\n\t// TODO: throw the SyntaxError (https://websockets.spec.whatwg.org/#dom-websocket-websocket)\n\turlString := urlValue.String()\n\turl, err := url.Parse(urlString)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"WebSocket requires valid url, but got %q which resulted in %w\", urlString, err)\n\t}\n\tif url.Scheme != \"ws\" && url.Scheme != \"wss\" {\n\t\treturn nil, fmt.Errorf(\"WebSocket requires url with scheme ws or wss, but got %q\", url.Scheme)\n\t}\n\tif url.Fragment != \"\" {\n\t\treturn nil, fmt.Errorf(\"WebSocket requires no url fragment, but got %q\", url.Fragment)\n\t}\n\n\treturn url, nil\n}\n","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/websockets/websockets.go#L145-L181","documentation":"Error \"WebSocket requires a url\" thrown in grafana/k6.","triggerScenarios":"Thrown at internal/js/modules/k6/websockets/websockets.go:163 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}