{"record":{"id":"bb7d21ad790e1184","repo":"grafana/k6","slug":"blob-arraybuffer-is-not-a-function","errorCode":null,"errorMessage":"Blob.[arrayBuffer] is not a function","messagePattern":"Blob\\.\\[arrayBuffer\\] is not a function","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/websockets/helpers.go","lineNumber":46,"sourceCode":"\treturn o.Prototype().Get(\"constructor\") == rt.GlobalObject().Get(\"Uint8Array\")\n}\n\nfunc isDataView(o *sobek.Object, rt *sobek.Runtime) bool {\n\treturn o.Prototype().Get(\"constructor\") == rt.GlobalObject().Get(\"DataView\")\n}\n\nfunc isBlob(o *sobek.Object, blobConstructor sobek.Value) bool {\n\treturn o.Prototype().Get(\"constructor\") == blobConstructor\n}\n\nfunc isObject(val sobek.Value) bool {\n\treturn val != nil && val.ExportType() != nil && val.ExportType().Kind() == reflect.Map\n}\n\nfunc extractBytes(o *sobek.Object, rt *sobek.Runtime) []byte {\n\tarrayBuffer, ok := sobek.AssertFunction(o.Get(\"arrayBuffer\"))\n\tif !ok {\n\t\tcommon.Throw(rt, errors.New(\"Blob.[arrayBuffer] is not a function\"))\n\t}\n\n\tbuffer, err := arrayBuffer(sobek.Undefined())\n\tif err != nil {\n\t\tcommon.Throw(rt, fmt.Errorf(\"call to Blob.[arrayBuffer] failed: %w\", err))\n\t}\n\n\tp, ok := buffer.Export().(*sobek.Promise)\n\tif !ok {\n\t\tcommon.Throw(rt, errors.New(\"Blob.[arrayBuffer] return is not a Promise\"))\n\t}\n\n\tab, ok := p.Result().Export().(sobek.ArrayBuffer)\n\tif !ok {\n\t\tcommon.Throw(rt, errors.New(\"Blob.[arrayBuffer] promise's return is not an ArrayBuffer\"))\n\t}\n\n\treturn ab.Bytes()","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/websockets/helpers.go#L28-L64","documentation":"Thrown when k6 needs the raw bytes of a Blob — during ws.send(blob) or when a Blob is nested in new Blob([existingBlob]) — and the object's arrayBuffer property is not callable. extractBytes (internal/js/modules/k6/websockets/helpers.go:46) is only reached after the object passed the Blob-constructor/prototype check, so it means something looks like a Blob but its arrayBuffer method is missing or shadowed.","triggerScenarios":"ws.send(obj) where obj passed isBlob (its prototype's constructor is Blob) but arrayBuffer was deleted or overridden with a non-function; feeding a Blob-like object from a shim into new Blob([blobLike]) so it hits the isBlob branch in fillData.","commonSituations":"Deleting or overriding Blob.prototype.arrayBuffer; a partially-implemented Blob polyfill or subclass mixed into the script; scripts written against a different k6 build whose Blob surface differs.","solutions":["Send a genuine Blob produced by k6's own constructor: ws.send(new Blob([data]))","If you subclass or wrap Blob, keep a working arrayBuffer() method that returns a Promise resolving to an ArrayBuffer","Convert the value to an ArrayBuffer or Uint8Array yourself and send that instead"],"exampleFix":"// before\nconst fakeBlob = Object.create(new Blob(['x']));\ndelete fakeBlob.arrayBuffer;\nws.send(fakeBlob);\n\n// after\nws.send(new Blob(['x']));","handlingStrategy":"type-guard","validationCode":"function asSendableBlob(v) {\n  if (v instanceof Blob) return v; // genuine k6 Blob\n  throw new TypeError(`expected a Blob created by k6, got ${Object.prototype.toString.call(v)}`);\n}\n\nws.send(asSendableBlob(value));","typeGuard":"function isRealBlob(v) {\n  return v instanceof Blob && typeof v.arrayBuffer === 'function';\n}","tryCatchPattern":null,"preventionTips":["Create Blobs only via new Blob(...) — never forge them with Object.create or raw prototypes","If you subclass Blob, keep arrayBuffer() intact or override it with the full Web contract","Convert foreign Blob-likes to ArrayBuffer/Uint8Array before ws.send()"],"tags":["websocket","blob","send","duck-typing","type-validation"],"backgroundTag":"invalid-blob-object","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}