grafana/k6 · error

parsing element handle click option modifiers: %w

Error message

parsing element handle click option modifiers: %w

What it means

Parsing the modifiers option of ElementHandle click-family options failed to export the value to []string. modifiers must be an array whose entries are strings (the recognized names are 'Alt', 'Control', 'Shift', 'Meta'); a non-array value or an array containing non-string entries makes rt.ExportTo fail.

Source

Thrown at internal/js/modules/k6/browser/common/element_handle_options.go:309

	if common.IsNullish(opts) {
		return nil
	}

	rt := k6ext.Runtime(ctx)
	obj := opts.ToObject(rt)
	for _, k := range obj.Keys() {
		switch k {
		case optionButton:
			o.Button = obj.Get(k).String()
		case optionClickCount:
			o.ClickCount = obj.Get(k).ToInteger()
		case optionDelay:
			o.Delay = obj.Get(k).ToInteger()
		case optionModifiers:
			var m []string
			if err := rt.ExportTo(obj.Get(k), &m); err != nil {
				return fmt.Errorf("parsing element handle click option modifiers: %w", err)
			}
			o.Modifiers = m
		}
	}

	return nil
}

func (o *ElementHandleClickOptions) ToMouseClickOptions() *MouseClickOptions {
	o2 := NewMouseClickOptions()
	o2.Button = o.Button
	o2.ClickCount = o.ClickCount
	o2.Delay = o.Delay
	return o2
}

func NewElementHandleDblclickOptions(defaultTimeout time.Duration) *ElementHandleDblclickOptions {
	return &ElementHandleDblclickOptions{

View on GitHub (pinned to 93accf6570)

Solutions

  1. Always pass modifiers as an array of strings: { modifiers: ['Shift'] }
  2. Use the exact names 'Alt', 'Control', 'Shift', 'Meta'
  3. If building dynamically, coerce each entry with String() and filter empties before passing

Example fix

// before
await page.click('#btn', { modifiers: 'Shift' });

// after
await page.click('#btn', { modifiers: ['Shift'] });
Defensive patterns

Strategy: validation

Validate before calling

const allowed = ['Alt', 'Control', 'Shift', 'Meta'];
const opts = { modifiers: ['Shift'] };
const valid = Array.isArray(opts.modifiers) && opts.modifiers.every(m => typeof m === 'string' && allowed.includes(m));
if (!valid) throw new Error('modifiers must be an array of Alt|Control|Shift|Meta');
await page.click('#btn', opts);

Type guard

function isModifierList(v) {
  const allowed = ['Alt', 'Control', 'Shift', 'Meta'];
  return v === undefined || (Array.isArray(v) && v.every(m => typeof m === 'string' && allowed.includes(m)));
}

Prevention

When it happens

Trigger: page.click('#id', { modifiers: 'Alt' }) — a bare string instead of an array; { modifiers: [1, 2] } with non-string entries; { modifiers: { Alt: true } } object form; dynamically built arrays that picked up null/undefined entries.

Common situations: Assuming a single modifier can be passed as a plain string; copying option shapes from other automation tools; building modifiers at runtime with push() of unvalidated values.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/6df6644fbd19f543. Report an issue: GitHub.