grafana/k6 · error
parsing locator dispatch event options
Error message
parsing locator dispatch event options: %w
What it means
Thrown by k6 browser's Locator.dispatchEvent(type, eventInit, options) when the options argument cannot be parsed by FrameDispatchEventOptions (a FrameBaseOptions that only recognizes 'timeout' and 'strict'). Parsing happens synchronously in the Go mapping layer before any CDP command is sent, so a failure aborts the call immediately. The error wraps the underlying conversion failure from Sobek, k6's JavaScript runtime.
Solutions
- Pass an options object literal with only supported keys: locator.dispatchEvent('click', {bubbles: true}, {timeout: 5000, strict: false}).
- Omit the third argument entirely (or pass null/undefined) to use the default timeout.
- Check the variable you pass as options is a plain object (typeof opts === 'object') before the call.
- If porting from Playwright, strip keys k6 does not parse (unknown keys are ignored anyway, but non-object values are not).
Example fix
// before
locator.dispatchEvent('click', {}, 5000);
// after
locator.dispatchEvent('click', {}, { timeout: 5000 }); Defensive patterns
Strategy: validation
Validate before calling
const ok = opts == null || (typeof opts === 'object' && !Array.isArray(opts));
if (!ok) throw new Error('dispatchEvent options must be an object, null, or undefined');
await locator.dispatchEvent('click', eventInit, opts ?? { timeout: 5000 }); Type guard
function isDispatchEventOptions(v) {
if (v == null) return true;
if (typeof v !== 'object' || Array.isArray(v)) return false;
return Object.keys(v).every(k => (k === 'timeout' || k === 'strict'));
} Try / catch
try { await locator.dispatchEvent('click', init, opts); } catch (e) { if (/parsing locator dispatch event options/.test(e.message)) { /* fix opts and retry or fail fast */ } throw e; } Prevention
- Always pass an object literal (or nothing) as the third argument of locator.dispatchEvent.
- Only set 'timeout' (integer ms) and 'strict' (boolean) keys in k6 dispatchEvent options.
- Type option objects in TypeScript as { timeout?: number; strict?: boolean } to catch mistakes at compile time.
When it happens
Trigger: Calling page.locator(...).dispatchEvent('click', {}, opts) with an opts value that Sobek cannot turn into an object (e.g. a BigInt like 100n or a Symbol), since null/undefined are allowed and plain numbers/strings get wrapped. Any error raised inside FrameBaseOptions.Parse (common/frame_options.go:218) while objectifying or reading keys also surfaces here.
Common situations: Porting Playwright scripts that pass option shapes k6's browser module does not accept; passing eventInit and options in swapped order so an unexpected value lands in the options slot; computed option variables that are undefined-but-not-null in edge cases.
Related errors
- dispatching element event
- missing required argument 'altText'
- missing required argument 'altText'
- missing required argument 'altText'
- missing required argument 'label'
AI-assisted analysis of grafana/k6@8d06114777 (2026-09-14).
Data as JSON: /api/errors/a3d485e6d7792202.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/browser/locator_mapping.go:419
return nil, fmt.Errorf("parsing hover options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, lo.Hover(copts) //nolint:wrapcheck
}), nil
},
"tap": func(opts sobek.Value) (*sobek.Promise, error) {
copts, err := parseFrameTapOptions(rt, opts, lo.DefaultTimeout())
if err != nil {
return nil, fmt.Errorf("parsing locator tap options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, lo.Tap(copts) //nolint:wrapcheck
}), nil
},
"dispatchEvent": func(typ string, eventInit, opts sobek.Value) (*sobek.Promise, error) {
popts, err := parseFrameDispatchEventOptions(rt, opts, lo.DefaultTimeout())
if err != nil {
return nil, fmt.Errorf("parsing locator dispatch event options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, lo.DispatchEvent(typ, exportArg(eventInit), popts) //nolint:wrapcheck
}), nil
},
"waitFor": func(opts sobek.Value) (*sobek.Promise, error) {
copts, err := parseFrameWaitForSelectorOptions(rt, opts, lo.Timeout())
if err != nil {
return nil, fmt.Errorf("parsing wait for options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, lo.WaitFor(copts) //nolint:wrapcheck
}), nil
},
}
}
func parseLocatorOptions(rt *sobek.Runtime, opts sobek.Value) *common.LocatorOptions {View on GitHub (pinned to 8d06114777)