grafana/k6 · error

parsing press options: %w

Error message

parsing press options: %w

What it means

Thrown when locator.press(key, opts) fails to parse options into FramePressOptions (delay number in ms, plus base keys force/noWaitAfter/timeout; strict). The mapping wraps the cause as 'parsing press options: %w'. Parsing is synchronous and lenient in current k6 (delay/timeout coerced via ToInteger), so this error indicates the opts slot held something that is not a plain options object.

Source

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

			}), nil
		},
		"selectOption": func(values sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
			copts := common.NewFrameSelectOptionOptions(lo.Timeout())
			if err := copts.Parse(vu.Context(), opts); 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 := common.NewFramePressOptions(lo.Timeout())
			if err := copts.Parse(vu.Context(), opts); 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 := common.NewFrameTypeOptions(lo.Timeout())
			if err := copts.Parse(vu.Context(), opts); 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 := common.NewFrameTypeOptions(lo.Timeout())

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass options as an object: press('Enter', { delay: 100, timeout: 5000 })
  2. Keep the key name as the first argument, never inside options
  3. Use numeric milliseconds for delay and timeout
  4. Omit options entirely when defaults suffice

Example fix

// before
await page.locator('#search').press('Enter', '100ms');

// after
await page.locator('#search').press('Enter', { delay: 100 });
Defensive patterns

Strategy: validation

Validate before calling

function assertPressOpts(opts) {
  if (opts === null || opts === undefined) return;
  if (typeof opts !== 'object' || Array.isArray(opts)) {
    throw new TypeError('press options must be a plain object');
  }
  for (const k of ['delay', 'timeout']) {
    if (k in opts && typeof opts[k] !== 'number') {
      throw new TypeError(`press ${k} must be a number (ms)`);
    }
  }
}

Type guard

function isPressOptions(v) {
  if (v === null || v === undefined) return true;
  if (typeof v !== 'object' || Array.isArray(v)) return false;
  return (v.delay === undefined || typeof v.delay === 'number') &&
         (v.timeout === undefined || typeof v.timeout === 'number');
}

Try / catch

try {
  await locator.press('Enter', opts);
} catch (e) {
  if (/parsing press options/.test(String(e.message))) {
    throw new Error(`Bad press options: ${JSON.stringify(opts)}`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling locator.press('Enter', 'fast') or press('Enter', 100) — scalar in the opts slot; passing { delay: '100ms' } under a strict parser; passing key names inside the options object ({ key: 'Enter' }) instead of as the first argument.

Common situations: Typing-speed delay passed as a duration string; ported Playwright snippets with slightly different argument order; options objects shared across press and type calls with incompatible keys.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/0447d6e70639377e. Report an issue: GitHub.