{"record":{"id":"7be4fe29b2e907a5","repo":"grafana/k6","slug":"options-must-be-an-object","errorCode":null,"errorMessage":"[options] must be an object","messagePattern":"\\[options\\] must be an object","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/websockets/blob.go","lineNumber":43,"sourceCode":"func (r *WebSocketsAPI) blob(call sobek.ConstructorCall) *sobek.Object {\n\trt := r.vu.Runtime()\n\n\tb := &blob{data: new(bytes.Buffer)}\n\tvar blobParts []any\n\tif len(call.Arguments) > 0 {\n\t\tif err := rt.ExportTo(call.Arguments[0], &blobParts); err != nil {\n\t\t\tcommon.Throw(rt, fmt.Errorf(\"failed to process [blobParts]: %w\", err))\n\t\t}\n\t}\n\n\tif len(blobParts) > 0 {\n\t\tr.fillData(b, blobParts, call)\n\t}\n\n\tif len(call.Arguments) > 1 && !sobek.IsUndefined(call.Arguments[1]) {\n\t\topts := call.Arguments[1]\n\t\tif !isObject(opts) {\n\t\t\tcommon.Throw(rt, errors.New(\"[options] must be an object\"))\n\t\t}\n\n\t\ttypeOpt := opts.ToObject(rt).Get(\"type\")\n\t\tif !sobek.IsUndefined(typeOpt) {\n\t\t\tb.typ = typeOpt.String()\n\t\t}\n\t}\n\n\tobj := rt.NewObject()\n\tmust(rt, obj.DefineAccessorProperty(\"size\", rt.ToValue(func() sobek.Value {\n\t\treturn rt.ToValue(b.data.Len())\n\t}), nil, sobek.FLAG_FALSE, sobek.FLAG_TRUE))\n\tmust(rt, obj.DefineAccessorProperty(\"type\", rt.ToValue(func() sobek.Value {\n\t\treturn rt.ToValue(b.typ)\n\t}), nil, sobek.FLAG_FALSE, sobek.FLAG_TRUE))\n\n\tmust(rt, obj.Set(\"arrayBuffer\", func(_ sobek.FunctionCall) sobek.Value {\n\t\tpromise, resolve, _ := rt.NewPromise()","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/websockets/blob.go#L25-L61","documentation":"Thrown by the Blob constructor in k6/experimental/websockets when the second (options) argument is present but is not a real object. The constructor skips only undefined; isObject (internal/js/modules/k6/websockets/helpers.go:41) requires an actual object, so strings, numbers, booleans — and null — all throw '[options] must be an object'. Browsers tolerate new Blob(parts, null); k6 does not.","triggerScenarios":"new Blob(['x'], 'text/plain'), new Blob(parts, 0), or new Blob(parts, null). A single-argument call new Blob(parts) is fine, as is passing undefined explicitly.","commonSituations":"Writing new Blob(parts, 'text/plain') instead of { type: 'text/plain' }; copying browser code that passes null as a defensive options value; a variable that was expected to hold an options object but holds a string.","solutions":["Pass an options object: new Blob(parts, { type: 'text/plain' })","Omit the second argument entirely when no options are needed","Never pass null for options in k6 — only undefined is skipped"],"exampleFix":"// before\nconst b = new Blob(['hello'], 'text/plain');\n\n// after\nconst b = new Blob(['hello'], { type: 'text/plain' });","handlingStrategy":"validation","validationCode":"function blobOptions(opts) {\n  if (opts === undefined) return undefined; // only undefined is skipped\n  if (opts === null || typeof opts !== 'object') {\n    throw new TypeError('[options] must be an object, e.g. { type: \\'text/plain\\' }');\n  }\n  return opts;\n}\n\nconst b = new Blob(['hello'], blobOptions(maybeOpts));","typeGuard":"function isPlainObject(v) {\n  return typeof v === 'object' && v !== null;\n}","tryCatchPattern":null,"preventionTips":["Always pass the options object literal: { type: 'text/plain' }","Do not reuse browser-style new Blob(parts, null) — k6 throws on null","Omit the second argument when there are no options"],"tags":["websocket","blob","constructor","arguments","type-validation"],"backgroundTag":"invalid-constructor-argument","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"}