{"record":{"id":"07b131e496347791","repo":"grafana/k6","slug":"websocket-requires-url-with-scheme-ws-or-wss-but","errorCode":null,"errorMessage":"WebSocket requires url with scheme ws or wss, but got %q","messagePattern":"WebSocket requires url with scheme ws or wss, but got %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/websockets/websockets.go","lineNumber":184,"sourceCode":"\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\nconst (\n\tarraybufferBinaryType = \"arraybuffer\"\n\tblobBinaryType        = \"blob\"\n)\n\n// defineWebsocket defines all properties and methods for the WebSocket\nfunc defineWebsocket(rt *sobek.Runtime, w *webSocket) {\n\tmust(rt, w.obj.DefineDataProperty(\n\t\t\"addEventListener\", rt.ToValue(w.addEventListener), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE))\n\tmust(rt, w.obj.DefineDataProperty(","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/grafana/k6/blob/165bb3c1a492b7a4823907fe1e93a30645794737/internal/js/modules/k6/websockets/websockets.go#L166-L202","documentation":"Scheme guard in the WebSocket constructor's URL parsing: the URL parsed successfully, but its scheme is neither ws nor wss. Passing an http://, https://, ftp://, or scheme-less URL to new WebSocket triggers this error, since the WebSocket protocol only operates over its own schemes.","triggerScenarios":"Thrown at internal/js/modules/k6/websockets/websockets.go:173 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Change the scheme to ws:// (plain) or wss:// (TLS) — e.g., https://example.com/ws becomes wss://example.com/ws","Derive the WebSocket URL from the page URL programmatically by replacing http with ws","Verify the endpoint is actually a WebSocket server before connecting"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"165bb3c1a492b7a4823907fe1e93a30645794737","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}