grafana/k6 · error
failed to create Blob: %w
Error message
failed to create Blob: %w
What it means
Wrap of a Sobek runtime constructor failure while materializing an incoming binary WebSocket message: when binaryType is "blob", the raw bytes are passed to the script's Blob constructor (new Blob([data])). The wrapped error fires when that constructor call throws in the JS runtime — commonly because the Blob global is shadowed, its arguments are invalid, or the runtime environment lacks the expected built-in.
Source
Thrown at internal/js/modules/k6/websockets/websockets.go:503
Metric: w.builtinMetrics.WSMessagesReceived,
Tags: w.tagsAndMeta.Tags,
},
Time: msg.t,
Metadata: w.tagsAndMeta.Metadata,
Value: 1,
})
rt := w.vu.Runtime()
ev := w.newEvent(events.MESSAGE, msg.t)
if msg.mtype == websocket.BinaryMessage {
var data any
switch w.binaryType {
case blobBinaryType:
var err error
data, err = rt.New(w.blobConstructor, rt.ToValue([]any{msg.data}))
if err != nil {
return fmt.Errorf("failed to create Blob: %w", err)
}
case arraybufferBinaryType:
data = rt.NewArrayBuffer(msg.data)
default:
return fmt.Errorf(`unknown binaryType %q, the supported ones are "blob" and "arraybuffer"`, w.binaryType)
}
must(rt, ev.DefineDataProperty("data", rt.ToValue(data), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE))
} else {
must(
rt,
ev.DefineDataProperty("data", rt.ToValue(string(msg.data)), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE),
)
}
must(
rt,
ev.DefineDataProperty("origin", rt.ToValue(w.url.String()), sobek.FLAG_FALSE, sobek.FLAG_FALSE, sobek.FLAG_TRUE),
)
View on GitHub (pinned to 165bb3c1a4)
Solutions
- Avoid shadowing or replacing the global Blob constructor in the script scope
- Switch ws.binaryType to "arraybuffer" to receive binary data without constructing a Blob
- Update k6 to a version whose runtime reliably provides the Blob constructor
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at internal/js/modules/k6/websockets/websockets.go:478 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@165bb3c1a4 (2026-08-18).
Data as JSON: /api/errors/bffb4ee170f369a1.
Report an issue: GitHub.