grafana/k6 · error

unpacking selected options: %w

Error message

unpacking selected options: %w

What it means

ElementHandle.SelectOption() succeeded at the protocol level but converting the returned selected-option list into []string failed (element_handle.go:1429). The convert() failure means the injected script returned an unexpected shape — an internal invariant break, not bad user input (bad values fail earlier with 'selecting options').

Source

Thrown at internal/js/modules/k6/browser/common/element_handle.go:1429

	return nil
}

// SelectOption selects the options matching the given values.
func (h *ElementHandle) SelectOption(values []any, opts *ElementHandleBaseOptions) ([]string, error) {
	selectOption := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
		return handle.selectOption(apiCtx, values)
	}
	selectOptionAction := h.newAction(
		[]string{}, selectOption, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,
	)
	selectedOptions, err := call(h.ctx, selectOptionAction, opts.Timeout)
	if err != nil {
		return nil, fmt.Errorf("selecting options: %w", err)
	}
	var returnVal []string
	if err := convert(selectedOptions, &returnVal); err != nil {
		return nil, fmt.Errorf("unpacking selected options: %w", err)
	}

	applySlowMo(h.ctx)

	return returnVal, nil
}

// SelectText selects the text of the element.
func (h *ElementHandle) SelectText(opts *ElementHandleBaseOptions) error {
	selectText := func(apiCtx context.Context, handle *ElementHandle) (any, error) {
		return nil, handle.selectText(apiCtx)
	}
	selectTextAction := h.newAction(
		[]string{}, selectText, opts.Force, withRetry, opts.NoWaitAfter, opts.Timeout,
	)
	if _, err := call(h.ctx, selectTextAction, opts.Timeout); err != nil {
		return fmt.Errorf("selecting text: %w", err)
	}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Upgrade k6 to the latest release
  2. If reproducible, file a k6 issue with the minimal select element and script
  3. Retry once — context-teardown races produce it transiently
  4. Read back state via inputValue()/evaluated DOM if you need the selection deterministically
Defensive patterns

Strategy: try-catch

Try / catch

try { return await el.selectOption('us'); }
catch (e) { if (/unpacking selected options/.test(e.message)) { return await el.evaluate(n => Array.from(n.selectedOptions).map(o => o.value)); } throw e; }

Prevention

When it happens

Trigger: A chromium/CDP deviation or k6 browser-module bug producing a non-string-array result from the select action; context destroyed between selection and value marshalling.

Common situations: Rare; correlated with chromium version changes or module regressions rather than with script logic.

Related errors


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