grafana/k6 · error

parsing press options

Error message

parsing press options: %w

What it means

Thrown synchronously when the options argument to locator.press(key, opts) fails to parse. The mapping (locator_mapping.go:368-372) builds common.FramePressOptions and wraps Parse failures as "parsing press options: %w". Parse (via ElementHandlePressOptions, element_handle_options.go:406-422) reads delay, noWaitAfter and timeout with coercing accessors and returns nil for ordinary values, so a real failure means sobek raised reading the object — a throwing getter, a Proxy trap, or a value whose numeric coercion throws.

Solutions

  1. Pass a plain literal: locator.press('Enter', { delay: 100, timeout: 5000 })
  2. Compute dynamic values before the call; no getters/Proxies on options
  3. Note the key argument itself is not validated here — a bad options object is
  4. try/catch the call for controlled failure handling

Example fix

// before
await locator.press('Enter', { get delay() { return cfg.delayMs; } }); // cfg undefined -> getter throws

// after
await locator.press('Enter', { delay: cfg?.delayMs ?? 0 });
Defensive patterns

Strategy: try-catch

Type guard

function isPlainPressOptions(o) {
  return o == null || (typeof o === 'object' &&
    (o.delay === undefined || Number.isFinite(o.delay)) &&
    (o.noWaitAfter === undefined || typeof o.noWaitAfter === 'boolean') &&
    (o.timeout === undefined || Number.isFinite(o.timeout)));
}

Try / catch

try {
  await locator.press('Enter', opts);
} catch (e) {
  throw new Error(`press failed (options must be plain delay/noWaitAfter/timeout numbers-booleans): ${e}`);
}

Prevention

When it happens

Trigger: A getter on delay/timeout that raises; Proxy-wrapped options with throwing traps; a delay/timeout value whose toPrimitive/valueOf throws during ToInteger coercion.

Common situations: Keyboard helpers building options from lazily-validated config; instrumentation Proxies over arguments; passing class instances with accessors where a literal is expected.

Related errors


AI-assisted analysis of grafana/k6@8d06114777 (2026-09-14). Data as JSON: /api/errors/0447d6e70639377e. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/browser/locator_mapping.go:372

			}), nil
		},
		"selectOption": func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
			copts, err := parseFrameSelectOptionOptions(rt, opts, lo.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing select option options: %w", err)
			}
			convValues, err := ConvertSelectOptionValues(vu.Runtime(), values)
			if err != nil {
				return nil, fmt.Errorf("parsing select option values: %w", err)
			}
			return promise(vu, func() (any, error) {
				return lo.SelectOption(convValues, copts) //nolint:wrapcheck
			}), nil
		},
		"press": func(key string, opts sobek.Value) (*sobek.Promise, error) {
			copts, err := parseFramePressOptions(rt, opts, lo.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing press options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, lo.Press(key, copts) //nolint:wrapcheck
			}), nil
		},

		"pressSequentially": func(text string, opts sobek.Value) (*sobek.Promise, error) {
			copts, err := parseFrameTypeOptions(rt, opts, lo.Timeout())
			if err != nil {
				return nil, fmt.Errorf("parsing locator press sequentially options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, lo.PressSequentially(text, copts) //nolint:wrapcheck
			}), nil
		},

		"type": func(text string, opts sobek.Value) (*sobek.Promise, error) {
			copts, err := parseFrameTypeOptions(rt, opts, lo.Timeout())

View on GitHub (pinned to 8d06114777)