grafana/k6 · error

parsing setChecked options

Error message

parsing setChecked options: %w

What it means

Thrown synchronously (before the promise is created) when ElementHandle.setChecked cannot parse its options object into ElementHandleSetCheckedOptions. The underlying parser (common/element_handle_options.go) coerces force/noWaitAfter/timeout/strict and silently ignores unknown keys, so the only realistic failure is the position field failing to export to a map[string]float64. In practice this means position was not a plain object with numeric values.

Solutions

  1. Pass position as numeric offsets from the element's top-left corner: {position: {x: 100, y: 50}}
  2. Omit position entirely to act on the element's default center point
  3. If options come from a variable, verify typeof opts.position === 'object' before the call

Example fix

// before
await handle.setChecked(true, { position: 'center' });
// after
await handle.setChecked(true, { position: { x: 100, y: 50 } });
Defensive patterns

Strategy: try-catch

Validate before calling

const validPos = (p) => p == null ||
  (typeof p === 'object' && !Array.isArray(p) && Number.isFinite(p.x) && Number.isFinite(p.y));
if (!validPos(opts.position)) {
  throw new Error(`invalid position ${JSON.stringify(opts.position)}; expected {x: number, y: number}`);
}
await handle.setChecked(true, opts);

Type guard

function isPointerPosition(v) {
  return v == null ||
    (typeof v === 'object' && !Array.isArray(v) &&
      Number.isFinite(v.x) && Number.isFinite(v.y));
}

Try / catch

try {
  await handle.setChecked(true, opts);
} catch (e) {
  if (String(e).includes('parsing setChecked options')) {
    // opts.position has the wrong shape; fix it and retry once
    delete opts.position;
    await handle.setChecked(true, opts);
  } else { throw e; }
}

Prevention

When it happens

Trigger: setChecked(true, {position: 'center'}), setChecked(true, {position: 10}), or setChecked(true, {position: {x: '10px', y: 20}}) — anything where position is not an object of number-valued keys x/y.

Common situations: Porting Playwright scripts that compute click positions as strings or CSS pixel values; building the options object dynamically (from JSON fixtures or env vars) so position ends up a string, number, or array; misunderstanding position as taking an element-relative keyword like 'center'.

Related errors


AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-09-14). Data as JSON: /api/errors/1f88f6ca3e106ae2. Report an issue: GitHub.

Appendix: source

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

				return nil, fmt.Errorf("parsing selectOption options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return eh.SelectOption(convValues, popts) //nolint:wrapcheck
			}), nil
		},
		"selectText": func(opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandleBaseOptions(eh.DefaultTimeout())
			if err := parseElementHandleBaseOptions(popts, rt, opts); err != nil {
				return nil, fmt.Errorf("parsing selectText options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.SelectText(popts) //nolint:wrapcheck
			}), nil
		},
		"setChecked": func(checked bool, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseElementHandleSetCheckedOptions(rt, opts, eh.DefaultTimeout())
			if err != nil {
				return nil, fmt.Errorf("parsing setChecked options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.SetChecked(checked, popts) //nolint:wrapcheck
			}), nil
		},
		"setInputFiles": func(files sobek.Value, opts sobek.Value) (*sobek.Promise, error) {
			popts, err := parseElementHandleSetInputFilesOptions(rt, opts, eh.DefaultTimeout())
			if err != nil {
				return nil, fmt.Errorf("parsing setInputFiles options: %w", err)
			}
			var pfiles common.Files
			if err := pfiles.Parse(vu.Context(), files); err != nil {
				return nil, fmt.Errorf("parsing setInputFiles parameter: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.SetInputFiles(&pfiles, popts) //nolint:wrapcheck
			}), nil
		},

View on GitHub (pinned to 3fcf5388d7)