grafana/k6 · error

parsing press %q options: %w

Error message

parsing press %q options: %w

What it means

Thrown synchronously by ElementHandle.press() when its options fail to parse. ElementHandlePressOptions (delay, noWaitAfter, timeout) is parsed with lenient coercions only and always returns nil in common/element_handle_options.go, so this wrap is defensive and effectively unreachable in current k6. Note the key argument itself is separate: an invalid key name fails later inside the promise (keyboard layer), not here.

Source

Thrown at internal/js/modules/k6/browser/browser/element_handle_mapping.go:167

		},
		"isVisible": func() *sobek.Promise {
			return promise(vu, func() (any, error) {
				return eh.IsVisible() //nolint:wrapcheck
			})
		},
		"ownerFrame": func() *sobek.Promise {
			return promise(vu, func() (any, error) {
				f, err := eh.OwnerFrame()
				if err != nil {
					return nil, err //nolint:wrapcheck
				}
				return mapFrame(vu, f), nil
			})
		},
		"press": func(key string, opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandlePressOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing press %q options: %w", key, err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.Press(key, popts) //nolint:wrapcheck
			}), nil
		},
		"screenshot": func(opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandleScreenshotOptions(eh.Timeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing element handle screenshot options: %w", err)
			}

			return promise(vu, func() (any, error) {
				bb, err := eh.Screenshot(popts, vu.filePersister)
				if err != nil {
					return nil, err //nolint:wrapcheck
				}

				ab := rt.NewArrayBuffer(bb)

View on GitHub (pinned to 93accf6570)

Solutions

  1. Use { delay: <ms>, noWaitAfter: <bool>, timeout: <ms> } with numeric milliseconds
  2. Verify the key string is a valid key name (e.g. 'Enter', 'ArrowDown', 'a') since invalid keys error later
  3. Upgrade k6 if this message appears, then re-check with an empty options object
  4. Inspect the wrapped cause after the colon for the actual failing field

Example fix

// before
await el.press('Enter', { timeout: '5s', delay: '100' });

// after
await el.press('Enter', { timeout: 5000, delay: 100 });
Defensive patterns

Strategy: try-catch

Validate before calling

if (opts) {
  if (opts.timeout !== undefined && !Number.isFinite(Number(opts.timeout))) throw new Error('press(): timeout must be ms number');
  if (opts.delay !== undefined && !Number.isFinite(Number(opts.delay))) throw new Error('press(): delay must be ms number');
}
const VALID = /^(Enter|Tab|Escape|Arrow(Up|Down|Left|Right)|Control|Shift|Alt|Meta|[a-zA-Z0-9])$/;
if (!VALID.test(key)) console.warn(`press(): unusual key name '${key}'`);

Type guard

function isPressOpts(o) {
  if (o == null) return true;
  return (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 el.press(key, opts);
} catch (e) {
  if (/parsing .* options/.test(String(e.message)) && e.message.includes(key)) {
    console.log(`fix press options: ${e.message}`);
  } else throw e; // invalid key names fail later inside the promise
}

Prevention

When it happens

Trigger: In current code none: delay/timeout coerce via ToInteger, noWaitAfter via ToBoolean, unknown keys are ignored. Older structural Parse builds could fail on mismatched field types.

Common situations: Passing timeout as '5s' (coerced to 0, not an error) and mistaking the resulting immediate timeout for a parse failure; ported Playwright code using press with extra unsupported options that are silently ignored.

Related errors


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