The mysterious Keyboard API of Chrome v68+

werner
2 min readAug 3, 2018

This may affect Cordova apps using the keyboard plugin (cordova-plugin-keyboard) or forks thereof. Basically anything that defines window.Keyboard

Today an issue was escalated my way that had some of our production users reporting an issue with one of our hybrid (Cordova) Android apps.

I fired up a debuggable APK of the app in question and attached my dev tools. It did not take long to see the issue — a TypeError being thrown even before the exception reporting code I implemented had a chance to catch it:

VM63:1 Uncaught TypeError: Keyboard.shrinkView is not a function

Strange I thought. Nothing changed and the last update pushed for this app was months ago. As far as I was concerned it was stable for a long time.

What I recall is that we used the Cordova keyboard plugin to have better control of the UX for this app — but that was beside the point.

Considering that WebView based apps post Android 5.0 basically uses a chrome-less Chrome tab to render in, I opened a tab in Chrome on my laptop to see if I could reproduce :

You can see navigator reporting Chrome/67.0.3396.99

Nope. Strange. So I checked the version of Chrome on the emulator I was using and it reported Chrome/68.0.3440.85

Hmmmm. So I update Chrome on my other laptop to version 68+ and run the same test :

It seems Chrome 68 introduced an undocumented Keyboard API

The fix was understandably easy, and a patch is already deployed.

I guess there are a few lessons in this:

  1. As developer, never trust that window.Somethingwill always be available.
  2. And even if it is available, do not assume it has the same interface as what you expect.
  3. If you develop Cordova plugins, please do not bind them to window — rather use window.cordova

Conclusion

I wonder what this Keyboard API is about?! Any takers?

--

--