grafana/k6 · error

unexpected DOM error type %T

Error message

unexpected DOM error type %T

What it means

errorFromDOMError is the translator for injected-script errors: it accepts only strings ('error:...' codes) or Go errors. This error means it received something else (nil, map, number — the %T shows which), an internal contract violation. One known path: the hit-target gate at element_handle.go:1762 wraps a possibly-nil error, and a nil value with %w surfaces as this shape; otherwise the injected script returned an unexpected payload.

Source

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

		return true, nil // Continue retrying after delay
	}
}

func errorFromDOMError(v any) error {
	var (
		err  error
		serr string
	)
	switch e := v.(type) {
	case string:
		serr = e
	case error:
		if e == nil {
			return errors.New("DOM error is nil")
		}
		err, serr = e, e.Error()
	default:
		return fmt.Errorf("unexpected DOM error type %T", v)
	}
	var uerr *k6ext.UserFriendlyError
	if errors.As(err, &uerr) {
		return err
	}
	if strings.Contains(serr, "timed out") {
		return &k6ext.UserFriendlyError{
			Err: ErrTimedOut,
		}
	}
	if s := "error:expectednode:"; strings.HasPrefix(serr, s) {
		return fmt.Errorf("expected node but got %s", strings.TrimPrefix(serr, s))
	}

	if serr == "error:notconnected" {
		return ErrElementNotAttachedToDOM
	}

View on GitHub (pinned to 93accf6570)

Solutions

  1. Re-run the script — most occurrences are transient races
  2. Upgrade to the latest k6 patch release; nil-wrapping in error paths has been an area of fixes
  3. If reproducible, run with K6_BROWSER_LOG=debug, note the %T type and the preceding action, and file a k6 issue
  4. As a workaround for click paths, force: true skips the hit-target gate where the nil-wrap originates
Defensive patterns

Strategy: retry

Try / catch

try {
  el.click();
} catch (e) {
  const msg = String(e);
  if (msg.includes('unexpected DOM error type') || msg.includes('%!w(<nil>)')) {
    el.click(); // transient race in the injected-script error path
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: checkHitTargetAt returning (false, nil) hit at the pointer-action gate (renders 'checking hit target: %!w(<nil>)'); injected-script evaluation returning an object/number where an error string was contracted; page-side prototype pollution corrupting injected script returns.

Common situations: Intermittent clicks on pages with overlays occasionally producing the nil-wrap path; testing pages that aggressively patch JS built-ins; essentially absent on well-behaved pages.

Related errors


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