grafana/k6 · error
inserting text: %w
Error message
inserting text: %w
What it means
Wrapper returned by Keyboard.InsertText when the private insertText() fails, i.e. the CDP Input.insertText call is rejected by the browser. insertText inserts text as IME-style input without individual key events, and fails at the transport level when the session or target is gone.
Source
Thrown at internal/js/modules/k6/browser/common/keyboard.go:83
}
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)
}
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)View on GitHub (pinned to 93accf6570)
Solutions
- Confirm the page is still open (page.isClosed() === false) before calling
- If the renderer crashed, re-launch/re-navigate and retry the fill
- Use type() when you also need key events fired (event handlers watching keydown)
- Wrap in try/catch and fail the iteration explicitly rather than continuing with partial input
Example fix
// before
await page.close();
await page.keyboard.insertText('done');
// after
if (!page.isClosed()) {
await page.keyboard.insertText('done');
} Defensive patterns
Strategy: try-catch
Validate before calling
if (page.isClosed()) throw new Error('page closed before insertText'); Try / catch
try {
await page.keyboard.insertText(text);
} catch (e) {
if (/inserting text/.test(e.message) && !page.isClosed()) {
await page.keyboard.insertText(text); // transient CDP failure: one retry
} else throw e;
} Prevention
- Check page liveness before insertText
- Complete text insertion before closing pages or ending the iteration
- Prefer insertText over long type() calls when key events are not needed
When it happens
Trigger: insertText('héllo') after page.close() or browser.close(); target crashed (renderer gone) before the call; CDP session detached while the input event is in flight.
Common situations: Using insertText for fast form filling after an earlier action already closed or crashed the page; races between script shutdown and pending input.
Related errors
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/ed7f2eed07b67e59.
Report an issue: GitHub.