grafana/k6 · error

parsing mouse down options

Error message

parsing mouse down options: %w

What it means

Thrown by mouse.down(options) when parseMouseDownUpOptions fails. The down/up parser (browser/mouse_mapping.go:124-145) accepts 'button' (string) and 'clickCount' (integer); a non-integer clickCount or a non-object options value is wrapped with this message. mouse.down is used for press-and-hold interaction sequences (often paired with mouse.move and mouse.up for drag).

Solutions

  1. Use an integer literal: page.mouse().down({ clickCount: 2 }).
  2. Coerce computed counts: Math.trunc(count) with a Number.isInteger guard.
  3. Omit clickCount (defaults to 1) for a simple press.
  4. Keep 'button' a string: 'left', 'right', or 'middle'.

Example fix

// before
await page.mouse().down({ clickCount: clicks }); // clicks = 2.0

// after
await page.mouse().down({ clickCount: Math.trunc(clicks) });
Defensive patterns

Strategy: validation

Validate before calling

const opts = clicks == null ? {} : { clickCount: Math.trunc(Number(clicks)) };
if (opts.clickCount != null && !Number.isInteger(opts.clickCount)) throw new Error('clickCount must be an integer');
await page.mouse().down(opts);

Type guard

function isDownUpOptions(o) {
  if (o == null) return true;
  if (typeof o !== 'object') return false;
  return (o.clickCount == null || Number.isInteger(o.clickCount)) && (o.button == null || typeof o.button === 'string');
}

Try / catch

try { await page.mouse().down(opts); } catch (e) { if (/parsing mouse down options|clickCount must be an integer/.test(e.message)) { await page.mouse().down({ clickCount: parseInt(opts.clickCount, 10) }); } else throw e; }

Prevention

When it happens

Trigger: page.mouse().down({ clickCount: 2.0 }) when 2.0 arrives as float64 from a computed value, { clickCount: '2' } from config, or a non-object argument in the options slot.

Common situations: Custom drag implementations that compute clickCount; multi-click press patterns ported from CDP scripts; options objects assembled dynamically where clickCount lost its integer type.

Related errors


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/4fad99d1bfea6e40. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/browser/mouse_mapping.go:37

				return nil, fmt.Errorf("parsing mouse click options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, m.Click(x, y, popts) //nolint:wrapcheck
			}), nil
		},
		"dblClick": func(x float64, y float64, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseMouseDblClickOptions(rt, opts)
			if err != nil {
				return nil, fmt.Errorf("parsing mouse double click options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, m.DblClick(x, y, popts) //nolint:wrapcheck
			}), nil
		},
		"down": func(opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseMouseDownUpOptions(rt, opts)
			if err != nil {
				return nil, fmt.Errorf("parsing mouse down options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, m.Down(popts) //nolint:wrapcheck
			}), nil
		},
		"up": func(opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseMouseDownUpOptions(rt, opts)
			if err != nil {
				return nil, fmt.Errorf("parsing mouse up options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, m.Up(popts) //nolint:wrapcheck
			}), nil
		},
		"move": func(x float64, y float64, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseMouseMoveOptions(rt, opts)
			if err != nil {
				return nil, fmt.Errorf("parsing mouse move options: %w", err)

View on GitHub (pinned to 01ffac6f24)