grafana/k6 · error

parsing uncheck options: %w

Error message

parsing uncheck options: %w

What it means

Thrown synchronously by ElementHandle.uncheck() when its options fail to parse. uncheck reuses ElementHandleSetCheckedOptions (base-pointer options plus strict), and in common/element_handle_options.go the only Parse step that can return an error is exporting 'position' to map[string]float64. As elsewhere in the mapping, the (nil, error) return surfaces as a synchronous JS exception, not a promise rejection.

Source

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

				if !ok {
					return nil, nil
				}
				return s, nil
			})
		},
		"type": func(text string, opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandleTypeOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing type options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.Type(text, popts) //nolint:wrapcheck
			}), nil
		},
		"uncheck": func(opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandleSetCheckedOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing uncheck options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.Uncheck(popts) //nolint:wrapcheck
			}), nil
		},
		"waitForElementState": func(state string, opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewElementHandleWaitForElementStateOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing waitForElementState options: %w", err)
			}
			return promise(vu, func() (any, error) {
				return nil, eh.WaitForElementState(state, popts) //nolint:wrapcheck
			}), nil
		},
		"waitForSelector": func(selector string, opts sobek.Value) (*sobek.Promise, error) {
			popts := common.NewFrameWaitForSelectorOptions(eh.DefaultTimeout())
			if err := popts.Parse(vu.Context(), opts); err != nil {
				return nil, fmt.Errorf("parsing waitForSelector %q options: %w", selector, err)

View on GitHub (pinned to 93accf6570)

Solutions

  1. Pass position as { x: <number>, y: <number> } or omit it to use the element center
  2. Normalize coordinates once with Number() and Number.isFinite validation
  3. Guard all pointer-action options with a shared isPosition helper
  4. Catch with try/catch around the call itself

Example fix

// before
await el.uncheck({ position: [4, 4] });

// after
await el.uncheck({ position: { x: 4, y: 4 } });
Defensive patterns

Strategy: type-guard

Validate before calling

const p = opts?.position;
if (p !== undefined && (typeof p !== 'object' || Array.isArray(p) ||
    !Number.isFinite(Number(p.x)) || !Number.isFinite(Number(p.y)))) {
  throw new Error('uncheck(): position must be { x: number, y: number }');
}

Type guard

function isUncheckOpts(o) {
  if (o == null) return true;
  const posOk = o.position === undefined ||
    (typeof o.position === 'object' && !Array.isArray(o.position) &&
     Number.isFinite(Number(o.position.x)) && Number.isFinite(Number(o.position.y)));
  const strictOk = o.strict === undefined || typeof o.strict === 'boolean';
  return posOk && strictOk;
}

Try / catch

try {
  await el.uncheck(opts);
} catch (e) {
  if (/parsing uncheck options/.test(String(e.message))) {
    console.log(`fix uncheck options: ${e.message}`);
  } else throw e;
}

Prevention

When it happens

Trigger: el.uncheck({ position: 'center' }), { position: { x: 5, y: '5' } }, or position as an array/number. strict/force/noWaitAfter/timeout are coercions and never trigger this.

Common situations: Sharing an options object between setChecked/check/uncheck call sites where one stored position as a string; coordinates read from external fixtures without numeric conversion.

Related errors


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