{"record":{"id":"71ffad568d0f1663","repo":"grafana/k6","slug":"typing-text-w","errorCode":null,"errorMessage":"typing text: %w","messagePattern":"typing text: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/keyboard.go","lineNumber":95,"sourceCode":"\treturn nil\n}\n\n// InsertText inserts a text without dispatching key events.\nfunc (k *Keyboard) InsertText(text string) error {\n\tif err := k.insertText(text); err != nil {\n\t\treturn fmt.Errorf(\"inserting text: %w\", err)\n\t}\n\treturn nil\n}\n\n// Type sends a press message to a session target for each character in text.\n// It delays the action if `Delay` option is specified.\n//\n// It sends an insertText message if a character is not among\n// valid characters in the keyboard's layout.\nfunc (k *Keyboard) Type(text string, kbdOpts KeyboardOptions) error {\n\tif err := k.typ(text, kbdOpts); err != nil {\n\t\treturn fmt.Errorf(\"typing text: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (k *Keyboard) down(key string) error {\n\tkey = k.platformSpecificResolution(key)\n\n\tkeyInput := keyboardlayout.KeyInput(key)\n\tif _, ok := k.layout.ValidKeys[keyInput]; !ok {\n\t\treturn fmt.Errorf(\"%q is not a valid key for layout %q\", key, k.layoutName)\n\t}\n\n\tkeyDef := k.keyDefinitionFromKey(keyInput)\n\tk.modifiers |= k.modifierBitFromKeyName(keyDef.Key)\n\ttext := keyDef.Text\n\n\tk.pressedKeysMu.Lock()\n\t_, autoRepeat := k.pressedKeys[keyDef.KeyCode]","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/keyboard.go#L77-L113","documentation":"Wrapper returned by Keyboard.Type when typ() fails. typ() iterates each character: valid layout keys go through press() (down+up with optional per-character delay), everything else falls back to insertText(). The error wraps a canceled wait during Delay, a failed per-character press, or a failed insertText fallback.","triggerScenarios":"type('héllo wörld', { delay: 100 }) where 'é'/'ö' take the insertText path and the session dies mid-string; a delay per character times the context out (delay * len > timeout); page closed while typing a long string.","commonSituations":"Typing long texts with per-character delay exceeding the browser action timeout; typing into a page whose beforeunload/navigation interrupts input; typing after the element was removed so the renderer target changed.","solutions":["Compute total time: type() with delay d and n chars blocks ~ n*d ms — keep it well under the timeout option","For pure text entry without key events, use insertText(text) once instead of per-character typing","Ensure the page stays open and no navigation occurs while typing","Catch and retry the full type() from a stable page state (input fields tolerate re-typing after clear())"],"exampleFix":"// before\nawait page.type('#msg', 'a very long status message', { delay: 500 }); // 500ms * ~28 chars\n\n// after\nawait page.keyboard.insertText('a very long status message'); // no per-char delay","handlingStrategy":"validation","validationCode":"const totalMs = text.length * (delayMs || 0) + text.length * 5; // heuristic per-char cost\nif (totalMs > actionTimeoutMs * 0.8) {\n  throw new Error('type() duration too close to timeout — lower delay or use insertText()');\n}\nif (page.isClosed()) throw new Error('page closed before type');","typeGuard":null,"tryCatchPattern":"try {\n  await page.keyboard.type(text, { delay });\n} catch (e) {\n  if (/typing text|pressing key|inserting text|context/.test(e.message)) {\n    await page.$eval(sel, 'el => el.value = \"\"');\n    await page.keyboard.type(text, { delay: 0 }); // retry faster from clean field\n  } else throw e;\n}","preventionTips":["Budget len(text) * delay against the timeout before typing","Use insertText() for long or non-ASCII strings","Ensure no navigation fires while typing (avoid search-as-you-type redirects)"],"tags":["browser","keyboard","input","timeout","cdp"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}