{"record":{"id":"68af91dbc4f25a09","repo":"grafana/k6","slug":"pressing-key-w","errorCode":null,"errorMessage":"pressing key: %w","messagePattern":"pressing key: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/keyboard.go","lineNumber":74,"sourceCode":"\t\treturn fmt.Errorf(\"sending key down: %w\", err)\n\t}\n\treturn nil\n}\n\n// Up sends a key up message to a session target.\nfunc (k *Keyboard) Up(key string) error {\n\tif err := k.up(key); err != nil {\n\t\treturn fmt.Errorf(\"sending key up: %w\", err)\n\t}\n\treturn nil\n}\n\n// Press sends a key press message to a session target.\n// It delays the action if `Delay` option is specified.\n// A press message consists of successive key down and up messages.\nfunc (k *Keyboard) Press(key string, kbdOpts KeyboardOptions) error {\n\tif err := k.comboPress(key, kbdOpts); err != nil {\n\t\treturn fmt.Errorf(\"pressing key: %w\", err)\n\t}\n\n\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.","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/browser/common/keyboard.go#L56-L92","documentation":"Wrapper returned by Keyboard.Press when comboPress fails. comboPress first waits opts.Delay (if > 0), then sends key-down for every key in the '+'-separated combo and key-up in reverse order. The error wraps either the initial wait being canceled (context deadline/cancel during delay), an invalid key in the combo, or a failed CDP dispatch.","triggerScenarios":"press('Control+C') where any segment ('Control', 'C') is not a valid layout key; press('Return'); press('Alt+Tab') with a delay long enough that the k6 iteration timeout cancels the context during the wait; page closed mid-combo leaving later dispatches failing.","commonSituations":"Copy/paste and modifier combos with wrong casing ('control' vs 'Control' — casing matters for layout names); long Delay values colliding with per-iteration timeouts; pressing after browser.close().","solutions":["Spell combo segments exactly as US-layout key names: 'Control+C', 'Shift+ArrowDown', 'Enter'","Keep opts.Delay small relative to the test/iteration timeout","Ensure the page is open and focused for the whole combo","Split ambiguous combos: '+' alone is the plus key, '++' means two plus presses — check split() semantics"],"exampleFix":"// before\nawait page.keyboard.press('control+c', { delay: 5000 });\n\n// after\nawait page.keyboard.press('Control+C');","handlingStrategy":"validation","validationCode":"const segments = combo.split('+');\n// note: a lone '+' is the plus key; '++' yields an empty invalid segment\nif (segments.some(s => s === '' && combo !== '+')) throw new Error(`bad combo: ${combo}`);\nif (segments.some(s => !isValidKey(s))) throw new Error(`invalid key in combo: ${combo}`);\nif (delayMs * segments.length > maxActionMs) throw new Error('combo delay exceeds timeout');","typeGuard":"function isValidCombo(combo) {\n  if (combo === '+') return true;\n  return combo.split('+').every(s => s !== '' && isValidKey(s));\n}","tryCatchPattern":"try {\n  await page.keyboard.press(combo, { delay });\n} catch (e) {\n  if (/not a valid key/.test(e.message)) throw new Error(`fix key names in combo '${combo}' (US-layout, exact casing)`);\n  throw e; // transport/context failure — check page state and retry\n}","preventionTips":["Validate every '+'-separated segment before pressing","Remember split() edge cases: '+' is plus, '++' contains an empty segment","Keep delay small relative to timeouts"],"tags":["browser","keyboard","input","validation","cdp"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}