{"record":{"id":"81cbedc976ffd026","repo":"grafana/k6","slug":"expected-arraybuffer-as-argument-received-s","errorCode":null,"errorMessage":"expected ArrayBuffer as argument, received: %s","messagePattern":"expected ArrayBuffer as argument, received: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/ws/ws.go","lineNumber":364,"sourceCode":"func (s *Socket) SendBinary(message sobek.Value) {\n\tif message == nil {\n\t\tcommon.Throw(s.rt, errors.New(\"missing argument, expected ArrayBuffer\"))\n\t}\n\n\tmsg := message.Export()\n\tif ab, ok := msg.(sobek.ArrayBuffer); ok {\n\t\tif err := s.conn.WriteMessage(websocket.BinaryMessage, ab.Bytes()); err != nil {\n\t\t\ts.handleEvent(\"error\", s.rt.ToValue(err))\n\t\t}\n\t} else {\n\t\tvar jsType string\n\t\tswitch {\n\t\tcase sobek.IsNull(message), sobek.IsUndefined(message):\n\t\t\tjsType = message.String()\n\t\tdefault:\n\t\t\tjsType = message.ToObject(s.rt).Get(\"constructor\").ToObject(s.rt).Get(\"name\").String()\n\t\t}\n\t\tcommon.Throw(s.rt, fmt.Errorf(\"expected ArrayBuffer as argument, received: %s\", jsType))\n\t}\n\n\tmetrics.PushIfNotDone(s.ctx, s.samplesOutput, metrics.Sample{\n\t\tTimeSeries: metrics.TimeSeries{\n\t\t\tMetric: s.builtinMetrics.WSMessagesSent,\n\t\t\tTags:   s.tagsAndMeta.Tags,\n\t\t},\n\t\tTime:     time.Now(),\n\t\tMetadata: s.tagsAndMeta.Metadata,\n\t\tValue:    1,\n\t})\n}\n\n// Ping sends a ping message over the websocket.\nfunc (s *Socket) Ping() {\n\tdeadline := time.Now().Add(writeWait)\n\tpingID := strconv.Itoa(s.pingSendCounter)\n\tdata := []byte(pingID)","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/ws/ws.go#L346-L382","documentation":"Thrown by ws.Socket.SendBinary when the argument exports to something other than a sobek.ArrayBuffer. The method first reports the missing-argument case separately; this error fires when a value was provided but is of the wrong type — the message includes the JS-side constructor name (or null/undefined) so you can see what was passed instead. The socket write is never attempted.","triggerScenarios":"Thrown at internal/js/modules/k6/ws/ws.go:364 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass an ArrayBuffer: socket.sendBinary(new TextEncoder().encode(data).buffer)","For a TypedArray, pass its .buffer property","Use socket.send() for string messages"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}