grafana/k6 · error

dispatching key event down

Error message

dispatching key event down: %w

What it means

Wrap of the CDP Input.dispatchKeyEvent (keyDown) command inside Keyboard.down: the key already passed layout validation and modifiers were tracked, so this wrap means the protocol call itself failed — the CDP session was closed or the context canceled (test iteration ending, page closing) while the event was being sent.

Solutions

  1. Ensure the page and session are open before dispatching key events
  2. Avoid key input during page navigation or teardown windows
  3. Retry the interaction on a fresh page if the session died unexpectedly
Defensive patterns

Strategy: retry

When it happens

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

Appendix: source

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

	k.pressedKeysMu.Unlock()

	keyType := input.KeyDown
	if text == "" {
		keyType = input.KeyRawDown
	}

	action := input.DispatchKeyEvent(keyType).
		WithModifiers(input.Modifier(k.modifiers)).
		WithKey(keyDef.Key).
		WithWindowsVirtualKeyCode(keyDef.KeyCode).
		WithCode(keyDef.Code).
		WithLocation(keyDef.Location).
		WithIsKeypad(keyDef.Location == 3).
		WithText(text).
		WithUnmodifiedText(text).
		WithAutoRepeat(autoRepeat)
	if err := action.Do(cdp.WithExecutor(k.ctx, k.session)); err != nil {
		return fmt.Errorf("dispatching key event down: %w", err)
	}

	return nil
}

func (k *Keyboard) up(key string) error {
	key = k.platformSpecificResolution(key)

	keyInput := keyboardlayout.KeyInput(key)
	if _, ok := k.layout.ValidKeys[keyInput]; !ok {
		return fmt.Errorf("'%s' is not a valid key for layout '%s'", key, k.layoutName)
	}

	keyDef := k.keyDefinitionFromKey(keyInput)
	k.modifiers &= ^k.modifierBitFromKeyName(keyDef.Key)
	k.pressedKeysMu.Lock()
	delete(k.pressedKeys, keyDef.KeyCode)
	k.pressedKeysMu.Unlock()

View on GitHub (pinned to 01ffac6f24)