iOS 9.2: WKWebView: JavaScript DOM element key events for some keys do not fire when triggered via external keyboard.

Originator:craig
Number:rdar://24071444 Date Originated:06-Jan-2016 12:20 PM
Status:Open Resolved:
Product:iOS SDK Product Version:9.2
Classification:Serious Bug Reproducible:Always
 
Summary:
This seems to date all the way back to the introduction of WKWebView but is present in the latest version of iOS. I have a WKWebView which contains a contenteditable element. I have various event listeners which fire when a key is pressed. When typing using an external Bluetooth keyboard for most keys this works fine, but for others (notably the tab and cursor keys) no events are fired. This is problematic because those of us wishing to make available keyboard shortcuts to our users cannot use common keystrokes (e.g. tab to indent, shift+tab to outdent).

I would hazard a guess that something in WebKit is trapping the key events to manage behaviour such as form navigation and so is not letting the events bubble up to user land.

Steps to Reproduce:
Example project which demonstrates the issue is here: 

https://github.com/Bipsync/ios-wkwebview-tab-events

Connect an external keyboard to an iOS device and run the project (I’ve reproduced this issue with an Apple model and a Logitech Ultrathin model). Tap the text on screen to bring up the keyboard. Press keys on the keyboard and observe the console in Xcode. For most keys (e.g. alphanumeric) some output should result as JavaScript events (keydown, keypress - keyup doesn’t seem to work but that’s not an issue) are fired. For other keys (e.g. tab and cursor keys) nothing happens.

Expected Results:
All keys (including tab and cursor though there are possibly others) should trigger the same events (keydown, keypress) as they would in a web browser such as Safari.

Actual Results:
Some keys do not trigger the keydown or keypress events.

Regression:
N/A. This has been the case since iOS 8.0.

Notes:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!