grafana/k6 · error
parsing element handle click option modifiers: %w
Error message
parsing element handle click option modifiers: %w
What it means
k6 browser's parseElementHandleClickOptions converts the JavaScript `modifiers` click option into a Go []string via rt.ExportTo. ExportTo fails when the Sobek value is not exportable as a string array (e.g. a string, number, or object), so k6 wraps the failure as 'parsing element handle click option modifiers'. Modifiers must be an array of key names such as 'Alt', 'Control', 'Meta', or 'Shift'.
Source
Thrown at internal/js/modules/k6/browser/browser/element_handle_mapping.go:609
err := parseElementHandleBasePointerOptions(&ehcopts.ElementHandleBasePointerOptions, rt, opts)
if err != nil {
return ehcopts, err
}
obj := opts.ToObject(rt)
for _, k := range obj.Keys() {
switch k {
case "button":
ehcopts.Button = obj.Get(k).String()
case "clickCount":
ehcopts.ClickCount = obj.Get(k).ToInteger()
case "delay":
ehcopts.Delay = obj.Get(k).ToInteger()
case "modifiers":
var m []string
if err := rt.ExportTo(obj.Get(k), &m); err != nil {
return ehcopts, fmt.Errorf("parsing element handle click option modifiers: %w", err)
}
ehcopts.Modifiers = m
}
}
return ehcopts, nil
}
// parseElementHandleBasePointerOptions parses the element handle base pointer options from a
// Sobek value into o.
func parseElementHandleBasePointerOptions(
o *common.ElementHandleBasePointerOptions, rt *sobek.Runtime, opts sobek.Value,
) error {
if k6common.IsNullish(opts) {
return nil
}
if err := parseElementHandleBaseOptions(&o.ElementHandleBaseOptions, rt, opts); err != nil {
return errView on GitHub (pinned to 8d06114777)
Solutions
- Pass modifiers as an array of strings, e.g. { modifiers: ['Shift'] }
- Verify the value type with Array.isArray(opts.modifiers) before calling click
- Check each element is a string (filter with typeof m === 'string')
- Remove the modifiers option entirely if not needed (it is optional)
Example fix
// before
await page.click('#submit', { modifiers: 'Shift' });
// after
await page.click('#submit', { modifiers: ['Shift'] }); Defensive patterns
Strategy: validation
Validate before calling
const MODIFIERS = ['Alt', 'Control', 'Meta', 'Shift'];
function validModifiers(opts) {
return opts == null || opts.modifiers === undefined ||
(Array.isArray(opts.modifiers) && opts.modifiers.every(m => typeof m === 'string' && MODIFIERS.includes(m)));
} Type guard
function isStringArray(v) {
return Array.isArray(v) && v.every(x => typeof x === 'string');
} Try / catch
try {
await page.click(sel, { modifiers: ['Shift'] });
} catch (e) {
if (String(e).includes('parsing element handle click option modifiers')) {
throw new Error('modifiers must be an array of strings, e.g. [\'Shift\']: ' + e);
}
throw e;
} Prevention
- Always wrap single modifiers in an array: ['Shift'], never 'Shift'
- Only use the supported modifier names: Alt, Control, Meta, Shift
- Unit-test option objects before passing them to click
- Validate option shapes with a helper before invoking browser APIs
When it happens
Trigger: Calling page.click or elementHandle.click with options where `modifiers` is not an array of strings: e.g. modifiers: 'Shift' (bare string), modifiers: 5, modifiers: {0:'Shift'} as a non-array object, or an array containing non-string elements that Sobek cannot export to []string.
Common situations: Copy-pasting Playwright snippets that pass a single modifier string instead of an array; building the modifiers array dynamically and accidentally producing a non-array; typos that assign another option's value to modifiers; template literals producing a string instead of an array.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- predicate function is not callable
- steps must be an integer, got %s
- missing required argument 'url'
- parsing click options: %w
- parsing waitForFunction options: %w
AI-assisted analysis of grafana/k6@8d06114777 (2026-09-14).
Data as JSON: /api/errors/a177973ace905741.
Report an issue: GitHub.