grafana/k6 · error
is not a valid key for layout
Error message
%q is not a valid key for layout %q
What it means
Layout-membership guard in Keyboard.down: before dispatching anything, the key string is resolved through platform-specific mappings and checked against the active keyboard layout's ValidKeys set ("us" layout by default). This error means the resolved key is not present in that set — a misspelled or non-existent key name like 'Del' instead of 'Delete', or an untranslated platform-specific key.
Solutions
- Use exact key names from the US layout: 'Delete', 'Backspace', 'ArrowLeft', 'PageDown', etc.
- Check the k6 browser keyboard documentation for the supported key list
- For single characters, use type()/insertText() rather than down()/up()
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/keyboard.go:105 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/e9713d90c24ea196.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/keyboard.go:105
// Type sends a press message to a session target for each character in text.
// It delays the action if `Delay` option is specified.
//
// It sends an insertText message if a character is not among
// valid characters in the keyboard's layout.
func (k *Keyboard) Type(text string, kbdOpts KeyboardOptions) error {
if err := k.typ(text, kbdOpts); err != nil {
return fmt.Errorf("typing text: %w", err)
}
return nil
}
func (k *Keyboard) down(key string) error {
key = k.platformSpecificResolution(key)
keyInput := keyboardlayout.KeyInput(key)
if _, ok := k.layout.ValidKeys[keyInput]; !ok {
return fmt.Errorf("%q is not a valid key for layout %q", key, k.layoutName)
}
keyDef := k.keyDefinitionFromKey(keyInput)
k.modifiers |= k.modifierBitFromKeyName(keyDef.Key)
text := keyDef.Text
k.pressedKeysMu.Lock()
_, autoRepeat := k.pressedKeys[keyDef.KeyCode]
k.pressedKeys[keyDef.KeyCode] = struct{}{}
k.pressedKeysMu.Unlock()
keyType := input.KeyDown
if text == "" {
keyType = input.KeyRawDown
}
action := input.DispatchKeyEvent(keyType).
WithModifiers(input.Modifier(k.modifiers)).View on GitHub (pinned to 01ffac6f24)