grafana/k6 · error
parsing element tap options: %w
Error message
parsing element tap options: %w
What it means
Thrown synchronously by ElementHandle.tap() when its options fail to parse. ElementHandleTapOptions embeds the base-pointer options plus modifiers; in common/element_handle_options.go only the 'position' export to map[string]float64 and the 'modifiers' export to []string can return an error. The mapping's (nil, error) return makes this a synchronous JS exception at call time.
Source
Thrown at internal/js/modules/k6/browser/browser/element_handle_mapping.go:246
}), nil
},
"setInputFiles": func(files sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
popts := common.NewElementHandleSetInputFilesOptions(eh.DefaultTimeout())
if err := popts.Parse(vu.Context(), opts); err != nil {
return nil, fmt.Errorf("parsing setInputFiles options: %w", err)
}
var pfiles common.Files
if err := pfiles.Parse(vu.Context(), files); err != nil {
return nil, fmt.Errorf("parsing setInputFiles parameter: %w", err)
}
return promise(vu, func() (any, error) {
return nil, eh.SetInputFiles(&pfiles, popts) //nolint:wrapcheck
}), nil
},
"tap": func(opts sobek.Value) (*sobek.Promise, error) {
popts := common.NewElementHandleTapOptions(eh.Timeout())
if err := popts.Parse(vu.Context(), opts); err != nil {
return nil, fmt.Errorf("parsing element tap options: %w", err)
}
return promise(vu, func() (any, error) {
return nil, eh.Tap(popts) //nolint:wrapcheck
}), nil
},
"textContent": func() *sobek.Promise {
return promise(vu, func() (any, error) {
s, ok, err := eh.TextContent()
if err != nil {
return nil, err //nolint:wrapcheck
}
if !ok {
return nil, nil
}
return s, nil
})
},
"type": func(text string, opts sobek.Value) (*sobek.Promise, error) {View on GitHub (pinned to 93accf6570)
Solutions
- Pass { position: { x: 8, y: 8 }, modifiers: ['Alt', 'Shift', 'Control', 'Meta'] } with correct types
- Coerce and validate coordinates/modifiers in setup before the browser session starts
- Reuse one shared type guard for all pointer actions (click, dblclick, hover, tap, check)
- Wrap calls in try/catch; the error is not a promise rejection
Example fix
// before
await el.tap({ position: '10,20', modifiers: 'Shift' });
// after
await el.tap({ position: { x: 10, y: 20 }, modifiers: ['Shift'] }); Defensive patterns
Strategy: type-guard
Validate before calling
if (opts) {
if (opts.position !== undefined &&
(typeof opts.position !== 'object' || Array.isArray(opts.position) ||
!Number.isFinite(Number(opts.position.x)) || !Number.isFinite(Number(opts.position.y)))) {
throw new Error('tap(): position must be { x: number, y: number }');
}
if (opts.modifiers !== undefined &&
!(Array.isArray(opts.modifiers) && opts.modifiers.every(m => typeof m === 'string'))) {
throw new Error('tap(): modifiers must be an array of strings');
}
} Type guard
function isTapOpts(o) {
if (o == null) return true;
const posOk = o.position === undefined ||
(typeof o.position === 'object' && !Array.isArray(o.position) &&
Number.isFinite(Number(o.position.x)) && Number.isFinite(Number(o.position.y)));
const modOk = o.modifiers === undefined ||
(Array.isArray(o.modifiers) && o.modifiers.every(m => typeof m === 'string'));
return posOk && modOk;
} Try / catch
try {
await el.tap(opts);
} catch (e) {
if (/parsing element tap options/.test(String(e.message))) {
console.log(`fix tap options: ${e.message}`);
} else throw e;
} Prevention
- Mobile-emulation coordinate sources (device metrics, env vars) often yield strings: coerce with Number() first
- Reuse the same pointer-options guard as click/hover/dblclick
- Remember the throw is synchronous; .catch() on the returned promise never sees it
When it happens
Trigger: el.tap({ position: 'topRight' }) or { position: { x: '8' } } (non-numeric coordinates), el.tap({ modifiers: 'Shift' }) or { modifiers: [1] } (modifiers not a string array). force/trial/timeout never fail parsing.
Common situations: Mobile-emulation scripts where coordinates come from device metrics as strings; reusing click/hover option literals with tap; modifiers supplied as a single string from environment variables.
Related errors
- parsing check options: %w
- parsing element click options: %w
- parsing element double click options: %w
- parsing element fill options: %w
- parsing element hover options: %w
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/faa7ee2b11c7cda2.
Report an issue: GitHub.