{"record":{"id":"31852c6ba9e95647","repo":"grafana/k6","slug":"sending-key-down-w","errorCode":null,"errorMessage":"sending key down: %w","messagePattern":"sending key down: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/keyboard.go","lineNumber":56,"sourceCode":"\tlayoutName    string // us by default\n\tlayout        keyboardlayout.KeyboardLayout\n}\n\n// NewKeyboard returns a new keyboard with a \"us\" layout.\nfunc NewKeyboard(ctx context.Context, s session) *Keyboard {\n\treturn &Keyboard{\n\t\tctx:         ctx,\n\t\tsession:     s,\n\t\tpressedKeys: make(map[int64]struct{}),\n\t\tlayoutName:  \"us\",\n\t\tlayout:      keyboardlayout.GetKeyboardLayout(\"us\"),\n\t}\n}\n\n// Down sends a key down message to a session target.\nfunc (k *Keyboard) Down(key string) error {\n\tif err := k.down(key); err != nil {\n\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)","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/keyboard.go#L38-L74","documentation":"Wrap of Keyboard.down in the public Keyboard.Down: the key is resolved against the active keyboard layout (\"us\" by default), and the wrap covers both failure modes of the inner call — an invalid key name for the layout, or the CDP Input.dispatchKeyEvent (keyDown) command failing because the session/context was closed.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/keyboard.go:56 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use standard key names as documented for the layout (e.g., 'a', 'Enter', 'ArrowDown')","Ensure the page and browser session are still open when sending key events","For combined shortcuts, prefer keyboard.press('Control+A') over manual down/up pairs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}