grafana/k6 · error
Blob.[arrayBuffer] return is not a Promise
Error message
Blob.[arrayBuffer] return is not a Promise
What it means
After calling arrayBuffer() on a Blob-like object, k6 requires the return value to be a Promise, because k6's own Blob.arrayBuffer resolves to an ArrayBuffer. extractBytes (internal/js/modules/k6/websockets/helpers.go:56) throws this when a Blob-shaped object's arrayBuffer() returns synchronously (raw bytes, a Uint8Array, or a plain value) instead of a Promise.
Solutions
- Make the override async (or return Promise.resolve(...)) so arrayBuffer() yields a Promise
- Send a real k6 Blob: ws.send(new Blob([data]))
- Extract the bytes to a Uint8Array in script code and send that directly
Example fix
// before
class MyBlob {
constructor(buf) { this.buf = buf; }
arrayBuffer() { return this.buf; } // synchronous — throws
}
ws.send(new MyBlob(bytes));
// after
class MyBlob {
constructor(buf) { this.buf = buf; }
async arrayBuffer() { return this.buf; } // returns a Promise
}
ws.send(new MyBlob(bytes)); Defensive patterns
Strategy: type-guard
Validate before calling
function checkBlobContract(v) {
if (!(v instanceof Blob)) return v;
const ret = v.arrayBuffer();
if (!(ret instanceof Promise)) {
throw new TypeError('arrayBuffer() must return a Promise — make the override async');
}
return v;
}
ws.send(checkBlobContract(value)); Type guard
function blobHasAsyncArrayBuffer(v) {
return v instanceof Blob && typeof v.arrayBuffer === 'function';
} Prevention
- Model Blob overrides on the Web contract: async arrayBuffer() resolving to an ArrayBuffer
- Run a one-line smoke check of any custom Blob (await blob.arrayBuffer()) before using it in sends
- Prefer k6's built-in Blob over shims from other runtimes
When it happens
Trigger: ws.send(obj) or new Blob([obj]) where obj's class overrides arrayBuffer as a plain method returning the bytes directly, e.g. arrayBuffer() { return this.buf; } — Node Buffer-style synchronous semantics instead of the Web Blob contract.
Common situations: A custom Blob shim written for older environments where arrayBuffer was synchronous; a subclass that 'optimizes away' the Promise; test doubles of Blob that forgot the async contract.
Related errors
- Blob.[arrayBuffer] is not a function
- Blob.[arrayBuffer] promise's return is not an ArrayBuffer
- [options] must be an object
- last argument to ws.connect must be a function
- browser.on promise rejected
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/2072b81526dd8283.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/websockets/helpers.go:56
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)