grafana/k6 · error
Blob.[arrayBuffer] is not a function
Error message
Blob.[arrayBuffer] is not a function
What it means
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.
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
Example fix
// before const fakeBlob = Object.create(new Blob(['x'])); delete fakeBlob.arrayBuffer; ws.send(fakeBlob); // after ws.send(new Blob(['x']));
Defensive patterns
Strategy: type-guard
Validate before calling
function asSendableBlob(v) {
if (v instanceof Blob) return v; // genuine k6 Blob
throw new TypeError(`expected a Blob created by k6, got ${Object.prototype.toString.call(v)}`);
}
ws.send(asSendableBlob(value)); Type guard
function isRealBlob(v) {
return v instanceof Blob && typeof v.arrayBuffer === 'function';
} Prevention
- 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()
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Blob.[arrayBuffer] return is not a Promise
- Blob.[arrayBuffer] promise's return is not an ArrayBuffer
- [options] must be an object
- InvalidStateError
- last argument to ws.connect must be a function
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/bb7d21ad790e1184.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/websockets/helpers.go:46
return o.Prototype().Get("constructor") == rt.GlobalObject().Get("Uint8Array")
}
func isDataView(o *sobek.Object, rt *sobek.Runtime) bool {
return o.Prototype().Get("constructor") == rt.GlobalObject().Get("DataView")
}
func isBlob(o *sobek.Object, blobConstructor sobek.Value) bool {
return o.Prototype().Get("constructor") == blobConstructor
}
func isObject(val sobek.Value) bool {
return val != nil && val.ExportType() != nil && val.ExportType().Kind() == reflect.Map
}
func extractBytes(o *sobek.Object, rt *sobek.Runtime) []byte {
arrayBuffer, ok := sobek.AssertFunction(o.Get("arrayBuffer"))
if !ok {
common.Throw(rt, errors.New("Blob.[arrayBuffer] is not a function"))
}
buffer, err := arrayBuffer(sobek.Undefined())
if err != nil {
common.Throw(rt, fmt.Errorf("call to Blob.[arrayBuffer] failed: %w", err))
}
p, ok := buffer.Export().(*sobek.Promise)
if !ok {
common.Throw(rt, errors.New("Blob.[arrayBuffer] return is not a Promise"))
}
ab, ok := p.Result().Export().(sobek.ArrayBuffer)
if !ok {
common.Throw(rt, errors.New("Blob.[arrayBuffer] promise's return is not an ArrayBuffer"))
}
return ab.Bytes()View on GitHub (pinned to 01ffac6f24)