{"record":{"id":"fd70e5cd118c5685","repo":"grafana/k6","slug":"websocket-requires-no-url-fragment-but-got-q","errorCode":null,"errorMessage":"WebSocket requires no url fragment, but got %q","messagePattern":"WebSocket requires no url fragment, but got %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/websockets/websockets.go","lineNumber":187,"sourceCode":"}\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(\n\t\t\"send\", rt.ToValue(w.send), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE))\n\tmust(rt, w.obj.DefineDataProperty(\n\t\t\"ping\", rt.ToValue(w.ping), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE))","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/grafana/k6/blob/165bb3c1a492b7a4823907fe1e93a30645794737/internal/js/modules/k6/websockets/websockets.go#L169-L205","documentation":"Fragment guard in the WebSocket constructor's URL parsing: per the WebSocket specification, a URL containing a #fragment is invalid for constructing a WebSocket because fragments are client-side only and never sent to the server. The error reports the offending URL string so the fragment can be located and removed.","triggerScenarios":"Thrown at internal/js/modules/k6/websockets/websockets.go:176 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Remove the #fragment portion from the WebSocket URL","If appending path or query parameters, use ?query syntax and URL-encode values","Sanitize URLs copied from browser devtools, which may include fragments"],"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-14T05:17:10.506Z"}