grafana/k6 · error

typing text

Error message

typing text: %w

What it means

Wrap of Keyboard.typ in the public Keyboard.Type: typing iterates each character, dispatching press events for layout-valid keys and falling back to insertText for characters outside the layout. This wrap means the loop failed partway — an invalid key path, an interrupted delay wait, or a CDP dispatch failure on a closed session. The inner error identifies which character and stage failed.

Solutions

  1. Prefer page.fill() or locator.fill() for plain text entry — faster and more robust
  2. Avoid typing while the page is navigating or closing
  3. Break very long strings into smaller type() calls to reduce exposure to mid-sequence failures
Defensive patterns

Strategy: try-catch

When it happens

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

Appendix: source

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

	return nil
}

// InsertText inserts a text without dispatching key events.
func (k *Keyboard) InsertText(text string) error {
	if err := k.insertText(text); err != nil {
		return fmt.Errorf("inserting text: %w", err)
	}
	return nil
}

// 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]

View on GitHub (pinned to 01ffac6f24)