grafana/k6 · error

key down

Error message

key down: %w

What it means

Wrap of Keyboard.down inside the single-key press helper: press() optionally waits the configured delay, dispatches key down, then key up. This wrap isolates the down-half failure — either the key failed layout validation (invalid name for the active layout) or the CDP dispatchKeyEvent call failed because the session/context was closed. It is the innermost wrap beneath Keyboard.Press's broader 'pressing key' error.

Solutions

  1. Use a valid, correctly-cased key name for the layout ('a', 'F5', 'Escape')
  2. Ensure the page session is alive when the press executes
  3. Prefer page/locator press helpers which manage focus and retries
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/keyboard.go:313 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/f70f7c01e7f5511f. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/browser/common/keyboard.go:313

			kk = append(kk, s.String())
			s.Reset()
		} else {
			s.WriteRune(r)
		}
	}
	kk = append(kk, s.String())

	return kk
}

func (k *Keyboard) press(key string, opts KeyboardOptions) error {
	if opts.Delay > 0 {
		if err := wait(k.ctx, opts.Delay); err != nil {
			return err
		}
	}
	if err := k.down(key); err != nil {
		return fmt.Errorf("key down: %w", err)
	}
	return k.up(key)
}

func (k *Keyboard) typ(text string, opts KeyboardOptions) error {
	layout := keyboardlayout.GetKeyboardLayout(k.layoutName)
	for _, c := range text {
		if opts.Delay > 0 {
			if err := wait(k.ctx, opts.Delay); err != nil {
				return err
			}
		}
		keyInput := keyboardlayout.KeyInput(c)
		if _, ok := layout.ValidKeys[keyInput]; ok {
			if err := k.press(string(c), opts); err != nil {
				return fmt.Errorf("pressing key: %w", err)
			}
			continue

View on GitHub (pinned to 01ffac6f24)