{"record":{"id":"c70c1b7059000f55","repo":"grafana/k6","slug":"options-expected-object-got-t","errorCode":null,"errorMessage":"options: expected object, got %T","messagePattern":"options: expected object, got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/browser/mapping.go","lineNumber":89,"sourceCode":"\t\t\t\t*valOpt.Value = item\n\t\t\t\tlabelOpt := common.SelectOption{Label: new(string)}\n\t\t\t\t*labelOpt.Label = item\n\t\t\t\topts = append(opts, &valOpt, &labelOpt)\n\t\t\tcase map[string]any:\n\t\t\t\topt, err := extractSelectOptionFromMap(item)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn nil, err\n\t\t\t\t}\n\n\t\t\t\topts = append(opts, opt)\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"options: expected string or object, got %T\", item)\n\t\t\t}\n\t\t}\n\tcase reflect.Map:\n\t\tvar raw map[string]any\n\t\tif err := rt.ExportTo(values, &raw); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"options: expected object, got %T\", values)\n\t\t}\n\n\t\topt, err := extractSelectOptionFromMap(raw)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\topts = append(opts, opt)\n\tcase reflect.TypeFor[*common.ElementHandle]().Kind():\n\t\topts = append(opts, t.(*common.ElementHandle)) //nolint:forcetypeassert\n\tcase reflect.TypeFor[sobek.Object]().Kind():\n\t\tobj := values.ToObject(rt)\n\t\topt := common.SelectOption{}\n\t\tfor _, k := range obj.Keys() {\n\t\t\tswitch k {\n\t\t\tcase \"value\":\n\t\t\t\topt.Value = new(string)\n\t\t\t\t*opt.Value = obj.Get(k).String()","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/browser/mapping.go#L71-L107","documentation":"Defensive branch inside ConvertSelectOptionValues: the values argument exported as a Go map kind, but sobek could not export it into map[string]any. Plain JavaScript object literals always export cleanly, so this guards non-standard map-like values (objects from native bindings, Proxy-wrapped objects, or corrupted runtime values). The rejection surfaces as 'parsing select option values: options: expected object, got <type>'.","triggerScenarios":"Passing a map-typed sobek value that is not a plain object literal as selectOption's single descriptor, e.g. an object produced by a Go/xk6 extension or a Proxy whose export fails.","commonSituations":"Interop with xk6 extensions supplying option descriptors; runtime/sobek upgrades altering export semantics.","solutions":["Pass a plain object literal: selectOption({ value: 'red' })","Rebuild descriptors from primitives: { value: String(obj.value), label: String(obj.label) }","Avoid Proxy or class instances in the values slot","Report reproducible cases to the k6 browser module"],"exampleFix":"// before\nawait page.locator('select').selectOption(proxyDescriptor);\n\n// after\nawait page.locator('select').selectOption({ value: String(proxyDescriptor.value) });","handlingStrategy":"type-guard","validationCode":"function toPlainDescriptor(v) {\n  if (typeof v !== 'object' || v === null || Array.isArray(v)) {\n    throw new TypeError(`selectOption descriptor must be a plain object, got ${typeof v}`);\n  }\n  const o = {};\n  if ('value' in v && v.value !== undefined) o.value = String(v.value);\n  if ('label' in v && v.label !== undefined) o.label = String(v.label);\n  if ('index' in v && v.index !== undefined) o.index = Number(v.index);\n  return o;\n}","typeGuard":"function isPlainSelectDescriptor(v) {\n  return typeof v === 'object' && v !== null &&\n    Object.getPrototypeOf(v) === Object.prototype;\n}","tryCatchPattern":"try {\n  await locator.selectOption(descriptor, opts);\n} catch (e) {\n  if (/expected object/.test(String(e.message))) {\n    await locator.selectOption({ value: String(descriptor?.value ?? '') }, opts);\n  } else {\n    throw e;\n  }\n}","preventionTips":["Build descriptors as plain object literals","Avoid Proxy/class instances in the values slot","Rebuild descriptors field-by-field from primitives"],"tags":["k6","browser","selectoption","type-validation","defensive"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}