grafana/k6 · error

sending key down

Error message

sending key down: %w

What it means

Wrap of Keyboard.down in the public Keyboard.Down: the key is resolved against the active keyboard layout ("us" by default), and the wrap covers both failure modes of the inner call — an invalid key name for the layout, or the CDP Input.dispatchKeyEvent (keyDown) command failing because the session/context was closed.

Solutions

  1. Use standard key names as documented for the layout (e.g., 'a', 'Enter', 'ArrowDown')
  2. Ensure the page and browser session are still open when sending key events
  3. For combined shortcuts, prefer keyboard.press('Control+A') over manual down/up pairs
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/common/keyboard.go:56 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/31852c6ba9e95647. Report an issue: GitHub.

Appendix: source

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

	layoutName    string // us by default
	layout        keyboardlayout.KeyboardLayout
}

// NewKeyboard returns a new keyboard with a "us" layout.
func NewKeyboard(ctx context.Context, s session) *Keyboard {
	return &Keyboard{
		ctx:         ctx,
		session:     s,
		pressedKeys: make(map[int64]struct{}),
		layoutName:  "us",
		layout:      keyboardlayout.GetKeyboardLayout("us"),
	}
}

// Down sends a key down message to a session target.
func (k *Keyboard) Down(key string) error {
	if err := k.down(key); err != nil {
		return fmt.Errorf("sending key down: %w", err)
	}
	return nil
}

// Up sends a key up message to a session target.
func (k *Keyboard) Up(key string) error {
	if err := k.up(key); err != nil {
		return fmt.Errorf("sending key up: %w", err)
	}
	return nil
}

// Press sends a key press message to a session target.
// It delays the action if `Delay` option is specified.
// A press message consists of successive key down and up messages.
func (k *Keyboard) Press(key string, kbdOpts KeyboardOptions) error {
	if err := k.comboPress(key, kbdOpts); err != nil {
		return fmt.Errorf("pressing key: %w", err)

View on GitHub (pinned to 01ffac6f24)