grafana/k6 · error

parsing mouse click options

Error message

parsing mouse click options: %w

What it means

Thrown by mouse.click(x, y, options) when the options object fails parseMouseClickOptions. That parser accepts only 'button' (any value, stringified), 'clickCount', and 'delay' — both integers — and requires the argument to be object-convertible (browser/mouse_mapping.go:63-95). Non-integer clickCount/delay (string, float, boolean) or a non-object options value surfaces wrapped in this message.

Solutions

  1. Use integer literals for clickCount and delay: { clickCount: 2, delay: 100 }.
  2. Round computed values: { delay: Math.round(jitterMs) }.
  3. Coerce config-sourced values: Number(cfg.delay) and verify Number.isInteger.
  4. Omit options entirely for a plain left click at the coordinates.

Example fix

// before
await page.mouse().click(10, 20, { clickCount: String(n), delay: jitter });

// after
await page.mouse().click(10, 20, { clickCount: parseInt(n, 10), delay: Math.round(jitter) });
Defensive patterns

Strategy: validation

Validate before calling

function mouseClickOpts(o = {}) {
  for (const k of ['clickCount', 'delay']) {
    if (o[k] != null && !Number.isInteger(o[k])) throw new Error(`${k} must be an integer, got ${o[k]}`);
  }
  return o;
}
await page.mouse().click(x, y, mouseClickOpts(cfg.mouse));

Type guard

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

Try / catch

try { await page.mouse().click(x, y, opts); } catch (e) { if (/parsing mouse click options|must be an integer/.test(e.message)) { /* coerce clickCount/delay to integers and retry */ } throw e; }

Prevention

When it happens

Trigger: page.mouse().click(10, 20, { clickCount: '2' }), { delay: 50.5 }, { delay: true }, or passing a number where options belongs. Note floats like 50.0 written as literals export as int64 and pass, but computed floats (50.5) fail.

Common situations: Delay values computed from pacing logic (e.g. jitter producing floats); options built from JSON config where all values are strings; fast clicks configured via clickCount read from a CSV.

Related errors


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

Appendix: source

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

package browser

import (
	"fmt"
	"reflect"

	"github.com/grafana/sobek"

	"go.k6.io/k6/v2/internal/js/modules/k6/browser/common"
	k6common "go.k6.io/k6/v2/js/common"
)

func mapMouse(vu moduleVU, m *common.Mouse) mapping {
	rt := vu.Runtime()
	return mapping{
		"click": func(x float64, y float64, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseMouseClickOptions(rt, opts)
			if err != nil {
				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)

View on GitHub (pinned to 01ffac6f24)