grafana/k6 · error
options: expected object, got %T
Error message
options: expected object, got %T
What it means
Thrown by ConvertSelectOptionValues when the selectOption argument classifies as an object/map (reflect.Map) but Sobek cannot export it to map[string]any (browser/mapping.go:89). The single-object form selectOption({value:'x'}) is valid, so this error means the map itself could not be read — typically a non-plain-object map-like value with non-string keys or an object from outside plain JS.
Solutions
- Use a plain object literal: page.selectOption('#sel', { value: 'blue' }).
- Convert Map instances first: Object.fromEntries(myMap).
- Keep keys to 'value', 'label', 'index' with correct value types (string, string, int).
- Verify with typeof obj === 'object' && !Array.isArray(obj) before the call.
Example fix
// before
await page.selectOption('#sel', new Map([['value', 'blue']]));
// after
await page.selectOption('#sel', { value: 'blue' }); Defensive patterns
Strategy: type-guard
Validate before calling
const obj = raw instanceof Map ? Object.fromEntries(raw) : raw;
await page.selectOption('#sel', typeof obj === 'object' && obj !== null ? obj : { value: String(raw) }); Type guard
function isPlainSelectObject(v) {
return v != null && typeof v === 'object' && !Array.isArray(v) && !(v instanceof Map) && !(v instanceof Set);
} Try / catch
try { await page.selectOption('#sel', obj); } catch (e) { if (/options: expected object/.test(e.message)) { await page.selectOption('#sel', Object.fromEntries(obj)); } else throw e; } Prevention
- Use object literals, not Map instances, for single selectOption descriptors.
- Keep descriptor keys limited to value, label, index.
- Normalize objects received from bindings with Object.fromEntries when needed.
When it happens
Trigger: Passing a Map instance with non-string keys, or an object produced by a Go binding whose export type is a map with non-string key types, to page.selectOption('#sel', obj). Plain JS object literals with string keys never trigger this.
Common situations: Using new Map([['value','x']]) instead of an object literal; receiving option descriptors from exported Go functions; almost never occurs with hand-written objects in a test script.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- options: expected array, got %T
- options: expected string or object, got %T
- options: unsupported type %T
- options[ ]: expected int, got %T
- options[ ]: expected string, got %T
AI-assisted analysis of grafana/k6@8d06114777 (2026-08-18).
Data as JSON: /api/errors/c70c1b7059000f55.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/mapping.go:97
*valOpt.Value = item
labelOpt := common.SelectOption{Label: new(string)}
*labelOpt.Label = item
opts = append(opts, &valOpt, &labelOpt)
case map[string]any:
opt, err := extractSelectOptionFromMap(item)
if err != nil {
return nil, err
}
opts = append(opts, opt)
default:
return nil, fmt.Errorf("options: expected string or object, got %T", item)
}
}
case reflect.Map:
var raw map[string]any
if err := rt.ExportTo(values, &raw); err != nil {
return nil, fmt.Errorf("options: expected object, got %T", values)
}
opt, err := extractSelectOptionFromMap(raw)
if err != nil {
return nil, err
}
opts = append(opts, opt)
case reflect.TypeFor[*common.ElementHandle]().Kind():
opts = append(opts, t.(*common.ElementHandle)) //nolint:forcetypeassert
case reflect.TypeFor[sobek.Object]().Kind():
obj := values.ToObject(rt)
opt := common.SelectOption{}
for _, k := range obj.Keys() {
switch k {
case "value":
opt.Value = new(string)
*opt.Value = obj.Get(k).String()View on GitHub (pinned to 8d06114777)