grafana/k6 · error

parsing type options: %w

Error message

parsing type options: %w

What it means

Thrown when locator.type(text, opts) fails to parse options into FrameTypeOptions (delay number in ms, timeout number in ms; strict). The mapping wraps the cause as 'parsing type options: %w'. locator.type is the deprecated predecessor of pressSequentially; the parser is lenient, so this error means the opts slot was not a valid plain options object.

Source

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

			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())
			if err := copts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing type options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, lo.Type(text, copts) //nolint:wrapcheck
			}), nil
		},
		"hover": func(opts sobek.Value) (*sobek.Promise, error) {
			copts := common.NewFrameHoverOptions(lo.Timeout())
			if err := copts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing hover options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, lo.Hover(copts) //nolint:wrapcheck
			}), nil
		},
		"tap": func(opts sobek.Value) (*sobek.Promise, error) {
			copts := common.NewFrameTapOptions(lo.DefaultTimeout())
			if err := copts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing locator tap options: %w", err)

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass a plain object: type('hello', { delay: 50 }) or omit the second argument
  2. Replace type() with pressSequentially(), its supported replacement, and verify the options shape there
  3. Use numeric milliseconds for delay and timeout
  4. Upgrade k6 so deprecated method warnings guide the migration

Example fix

// before
await page.locator('input').type('k6', '50ms');

// after
await page.locator('input').pressSequentially('k6', { delay: 50 });
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

function isTypeOptions(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.type(text, opts);
} catch (e) {
  if (/parsing type options/.test(String(e.message))) {
    throw new Error(`Bad type options: ${JSON.stringify(opts)}`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling locator.type('hello', '50ms') or type('hello', 50) — scalar in the opts slot; wrong-typed delay/timeout on strict k6 builds; passing the text positionally into options.

Common situations: Older example scripts and blog posts using type(); migrating them while carrying string durations; mixing fill() and type() call signatures.

Related errors


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