{"record":{"id":"e5d15e22f7574998","repo":"grafana/k6","slug":"dispatching-key-event-down-w","errorCode":null,"errorMessage":"dispatching key event down: %w","messagePattern":"dispatching key event down: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/keyboard.go","lineNumber":133,"sourceCode":"\tk.pressedKeysMu.Unlock()\n\n\tkeyType := input.KeyDown\n\tif text == \"\" {\n\t\tkeyType = input.KeyRawDown\n\t}\n\n\taction := input.DispatchKeyEvent(keyType).\n\t\tWithModifiers(input.Modifier(k.modifiers)).\n\t\tWithKey(keyDef.Key).\n\t\tWithWindowsVirtualKeyCode(keyDef.KeyCode).\n\t\tWithCode(keyDef.Code).\n\t\tWithLocation(keyDef.Location).\n\t\tWithIsKeypad(keyDef.Location == 3).\n\t\tWithText(text).\n\t\tWithUnmodifiedText(text).\n\t\tWithAutoRepeat(autoRepeat)\n\tif err := action.Do(cdp.WithExecutor(k.ctx, k.session)); err != nil {\n\t\treturn fmt.Errorf(\"dispatching key event down: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (k *Keyboard) up(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(\"'%s' is not a valid key for layout '%s'\", key, k.layoutName)\n\t}\n\n\tkeyDef := k.keyDefinitionFromKey(keyInput)\n\tk.modifiers &= ^k.modifierBitFromKeyName(keyDef.Key)\n\tk.pressedKeysMu.Lock()\n\tdelete(k.pressedKeys, keyDef.KeyCode)\n\tk.pressedKeysMu.Unlock()","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/keyboard.go#L115-L151","documentation":"Wrap of the CDP Input.dispatchKeyEvent (keyDown) command inside Keyboard.down: the key already passed layout validation and modifiers were tracked, so this wrap means the protocol call itself failed — the CDP session was closed or the context canceled (test iteration ending, page closing) while the event was being sent.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/keyboard.go:133 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the page and session are open before dispatching key events","Avoid key input during page navigation or teardown windows","Retry the interaction on a fresh page if the session died unexpectedly"],"exampleFix":null,"handlingStrategy":"retry","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"}