grafana/k6 · error

parsing mouse move options

Error message

parsing mouse move options: %w

What it means

Thrown by mouse.move(x, y, options) when parseMouseMoveOptions fails. The move parser (browser/mouse_mapping.go:148+, following the same manual key loop as the other mouse parsers) reads 'steps' as an integer; a non-integer steps value or a non-object options argument is wrapped with this message before the movement is dispatched.

Solutions

  1. Pass an integer: { steps: 5 } or omit steps for a single jump.
  2. Round computed steps: { steps: Math.max(1, Math.round(dist / stepSize)) }.
  3. Coerce env/config values with Number() and verify Number.isInteger before the call.
  4. Remember steps < 1 is pointless — clamp to at least 1.

Example fix

// before
await page.mouse().move(200, 200, { steps: dist / 40 }); // 4.75

// after
await page.mouse().move(200, 200, { steps: Math.max(1, Math.round(dist / 40)) });
Defensive patterns

Strategy: validation

Validate before calling

const steps = raw == null ? undefined : Math.max(1, Math.round(Number(raw.steps)));
await page.mouse().move(x, y, steps ? { steps } : undefined);

Type guard

function isMoveOptions(o) {
  if (o == null) return true;
  if (typeof o !== 'object') return false;
  return o.steps == null || Number.isInteger(o.steps);
}

Try / catch

try { await page.mouse().move(x, y, { steps }); } catch (e) { if (/parsing mouse move options|steps must be an integer/.test(e.message)) { await page.mouse().move(x, y, { steps: Math.round(steps) }); } else throw e; }

Prevention

When it happens

Trigger: page.mouse().move(10, 20, { steps: '5' }) or { steps: 2.5 } — steps interpolates intermediate points between the current and target position, so pacing code that computes fractional steps is the usual source; non-object values in the options slot also fail.

Common situations: Steps computed from distance/velocity math producing floats; config-driven step counts parsed as strings from env vars; porting drag helpers from Playwright where steps semantics match but typing differs.

Related errors


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

Appendix: source

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

				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)
			}
			return promise(vu, func() (any, error) {
				return nil, m.Move(x, y, popts) //nolint:wrapcheck
			}), nil
		},
	}
}

// parseMouseClickOptions parses the mouse click options from a Sobek value.
func parseMouseClickOptions(rt *sobek.Runtime, opts sobek.Value) (*common.MouseClickOptions, error) {
	popts := common.NewMouseClickOptions()
	if k6common.IsNullish(opts) {
		return popts, nil
	}

	obj := opts.ToObject(rt)
	for _, k := range obj.Keys() {
		v := obj.Get(k)

View on GitHub (pinned to 01ffac6f24)