grafana/k6 · error
' ' is not a valid key for layout
Error message
'%s' is not a valid key for layout '%s'
What it means
Layout-membership guard in Keyboard.up, the release counterpart of the down guard: the key string is checked against the active layout's ValidKeys set, and this error means the key being released is not a recognized key name for that layout. Note it can surface for a valid press key if the up call uses different spelling or casing (e.g., pressing 'Enter' but releasing 'enter').
Solutions
- Use identical, correctly-cased key names for down and up ('Enter', 'Shift', 'ArrowUp')
- Prefer press() which derives the release key from the press key automatically
- Consult the supported key list in the k6 browser docs
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/keyboard.go:144 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/449686a8cfdf2582.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/keyboard.go:144
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()
action := input.DispatchKeyEvent(input.KeyUp).
WithModifiers(input.Modifier(k.modifiers)).
WithKey(keyDef.Key).
WithWindowsVirtualKeyCode(keyDef.KeyCode).
WithCode(keyDef.Code).
WithLocation(keyDef.Location)
if err := action.Do(cdp.WithExecutor(k.ctx, k.session)); err != nil {
return fmt.Errorf("dispatching key event up: %w", err)
}
View on GitHub (pinned to 01ffac6f24)