grafana/k6 · error
parsing focus options
Error message
parsing focus options: %w
What it means
Thrown synchronously when the options argument to locator.focus() fails to parse. The mapping (locator_mapping.go:210-214) creates common.NewFrameBaseOptions(lo.Timeout()) and wraps any Parse failure as "parsing focus options: %w". FrameBaseOptions.Parse handles only strict and timeout via boolean/integer coercion and cannot fail on plain wrong-typed values, so the wrapped error means sobek itself raised reading the object — throwing getter, Proxy trap, or a value whose coercion throws.
Solutions
- Call locator.focus() with no argument or a plain literal { timeout: ms }
- Replace accessors with plain properties computed before the call
- Do not hand Proxy-wrapped objects to browser module APIs
- Catch synchronously with try/catch if inputs are untrusted
Example fix
// before
await locator.focus({ get timeout() { return getCfg('timeout'); } }); // getter throws on missing key
// after
const timeout = getCfg('timeout');
await locator.focus({ timeout }); Defensive patterns
Strategy: try-catch
Type guard
function isPlainBaseOptions(o) {
return o == null || (typeof o === 'object' &&
(o.timeout === undefined || typeof o.timeout === 'number') &&
(o.strict === undefined || typeof o.strict === 'boolean'));
} Try / catch
try {
await locator.focus(opts);
} catch (e) {
throw new Error(`focus failed (options must be plain { timeout, strict }): ${e}`);
} Prevention
- Call focus() with no options when defaults suffice
- Resolve timeout config before building the object
- Keep options free of Proxy/accessor machinery
When it happens
Trigger: opts.timeout defined as a throwing getter; a Proxy around options with raising traps; a timeout whose toPrimitive raises during ToInteger.
Common situations: Focus wrappers in page objects that build options via accessors; debugging Proxies; passing the result of Object.create with getter prototypes.
Related errors
- parsing fill options
- parsing focus options
- parsing focus options
- parsing get attribute options
- parsing hover options
AI-assisted analysis of grafana/k6@8d06114777 (2026-09-14).
Data as JSON: /api/errors/f78d69ee411013a4.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/locator_mapping.go:213
return nil, fmt.Errorf("parsing fill options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, lo.Fill(value, copts) //nolint:wrapcheck
}), nil
},
"filter": func(opts sobek.Value) mapping {
return mapLocator(vu, lo.Filter(&common.LocatorFilterOptions{
LocatorOptions: parseLocatorOptions(rt, opts),
}))
},
"first": func() *sobek.Object {
ml := mapLocator(vu, lo.First())
return rt.ToValue(ml).ToObject(rt)
},
"focus": func(opts sobek.Value) (*sobek.Promise, error) {
copts := common.NewFrameBaseOptions(lo.Timeout())
if err := parseFrameBaseOptions(copts, rt, opts); err != nil {
return nil, fmt.Errorf("parsing focus options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, lo.Focus(copts) //nolint:wrapcheck
}), nil
},
"getAttribute": func(name string, opts sobek.Value) (*sobek.Promise, error) {
copts := common.NewFrameBaseOptions(lo.Timeout())
if err := parseFrameBaseOptions(copts, rt, opts); err != nil {
return nil, fmt.Errorf("parsing get attribute options: %w", err)
}
return promise(vu, func() (any, error) {
s, ok, err := lo.GetAttribute(name, copts)
if err != nil {
return nil, err //nolint:wrapcheck
}
if !ok {
return nil, nil
}View on GitHub (pinned to 8d06114777)