{"record":{"id":"22feeeb4d16277c2","repo":"grafana/k6","slug":"blob-arraybuffer-promise-s-return-is-not-an-arra","errorCode":null,"errorMessage":"Blob.[arrayBuffer] promise's return is not an ArrayBuffer","messagePattern":"Blob\\.\\[arrayBuffer\\] promise's return is not an ArrayBuffer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/websockets/helpers.go","lineNumber":61,"sourceCode":"func 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()\n}\n","sourceCodeStart":43,"sourceCodeEnd":66,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/websockets/helpers.go#L43-L66","documentation":"The last step of Blob byte extraction in k6: after arrayBuffer() returns a Promise, its settled result must be an ArrayBuffer. extractBytes (internal/js/modules/k6/websockets/helpers.go:61) throws this when the Promise resolves to a Uint8Array, a string, or any other value — a Uint8Array is not an ArrayBuffer even though it wraps one.","triggerScenarios":"ws.send(obj) or new Blob([obj]) where the object's async arrayBuffer() resolves to new Uint8Array(n) rather than new Uint8Array(n).buffer.","commonSituations":"Blob shims that resolve with typed arrays (common in Node-era polyfills); forgetting the .buffer accessor when adapting view types; test doubles returning already-copied byte arrays.","solutions":["Resolve with the underlying buffer: async arrayBuffer() { return this.bytes.buffer; }","Send a genuine k6 Blob built from the data: ws.send(new Blob([data]))","Pre-convert the object to an ArrayBuffer/Uint8Array in the script and pass that to send()"],"exampleFix":"// before\nclass MyBlob {\n  async arrayBuffer() { return new Uint8Array([1, 2, 3]); } // resolves to a view\n}\n\n// after\nclass MyBlob {\n  async arrayBuffer() { return new Uint8Array([1, 2, 3]).buffer; } // resolves to an ArrayBuffer\n}","handlingStrategy":"type-guard","validationCode":"async function assertBlobResolvesArrayBuffer(v) {\n  if (!(v instanceof Blob)) return v;\n  const out = await v.arrayBuffer();\n  if (!(out instanceof ArrayBuffer)) {\n    throw new TypeError('arrayBuffer() must resolve to an ArrayBuffer, not a typed array');\n  }\n  return v;\n}\n\nws.send(await assertBlobResolvesArrayBuffer(value));","typeGuard":"async function resolvesArrayBuffer(v) {\n  if (!(v instanceof Blob)) return false;\n  const out = await v.arrayBuffer();\n  return out instanceof ArrayBuffer;\n}","tryCatchPattern":null,"preventionTips":["Return this.bytes.buffer (not this.bytes) from custom arrayBuffer() overrides","Remember a Uint8Array is a view, not an ArrayBuffer — the extraction checks the exact type","Unit-test custom Blob shims against: await blob.arrayBuffer() instanceof ArrayBuffer"],"tags":["websocket","blob","arraybuffer","promise","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"}