Bug 195884

Summary: Autofocus on text input does not show keyboard
Product: WebKit Reporter: pza1
Component: WebKit APIAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Critical CC: craig, dbates, krevis, landsman, steve, webkit-bug-importer, wenson_hsieh
Priority: P1 Keywords: InRadar
Version: Safari 12   
Hardware: iPhone / iPad   
OS: iOS 12   
See Also: https://bugs.webkit.org/show_bug.cgi?id=190017

Description pza1 2019-03-18 06:41:26 PDT
The javascript focus function does not display the keyboard when it is used outside Touch events, e.g. after being performed by the WKWebView method evaluateJavaScript.
Comment 1 pza1 2019-03-18 07:18:08 PDT
Example code:

webView.evaluateJavaScript("document.getElementById('someElement').focus()", completionHandler: nil)

after that element is focused, but the keyboard does not appear.
Comment 2 pza1 2019-03-18 07:18:22 PDT
Our customers already experienced this problem on their production sites. This feature is critical in case of web application using scanning where users do not want to touch the screen each time they scan something. From user perspective screen should open with focused input and all they need is just hit scan button (e.g. etui with integrated scanner device).
Comment 3 Radar WebKit Bug Importer 2019-03-19 15:41:40 PDT
<rdar://problem/49039049>
Comment 4 Daniel Bates 2019-03-19 17:21:29 PDT
So, I've got some good news 🙂 and some bad news 🙁 for you. Let's do good news first:

Following the fix in bug #190017 we now allow programmatic focus if you have a hardware keyboard attached (i.e. calling .focus() in JavaScript will do something now! 🎉)

Now the bad news:

We (Apple) like the current behavior and do not want programmatic focus to bring up the keyboard when you do not have a hardware keyboard attached and the programmatic focus was not invoked in response to a user gesture. Why you may ask...because auto bringing up the software keyboard can be seen as annoying and a distraction to a user (not for your customers, but for everyone not using your app) given that:

1. We bring up the keyboard, which takes up valuable real estate on screen.
2. When we intent to bring up the software keyboard we zoom and scroll the page to give a pleasing input experience (or at least we hope it is pleasing; file bugs if not).

But you're an app developer and are embedding a WKWebView you say... you may be in luck 🍀. I could swear we have API you can toggle to tell WebKit you are OK with auto-showing the keyboard, CC'ing Wenson as maybe my memory is wrong or it's SPI ("private API") or it's non-existent. If we don't have such API then there is still hope for you, re-title this bug, and re-phrase this request as an enhancement. Otherwise, as this bug is titled and worded now it is destined for Resolved Not To Be Fixed.
Comment 5 Kurt Revis 2022-08-15 15:46:09 PDT
I believe this was fixed in iOS 16 beta 6 by:
https://bugs.webkit.org/show_bug.cgi?id=243416
Comment 6 Wenson Hsieh 2022-08-15 15:50:18 PDT
(In reply to Kurt Revis from comment #5)
> I believe this was fixed in iOS 16 beta 6 by:
> https://bugs.webkit.org/show_bug.cgi?id=243416

Hi Kurt! Just to clarify — that change indeed makes it so that programmatic focus triggered directly by the embedding client (e.g. via `-evaluateJavaScript:completionHandler:`) will now show the keyboard by default; however, this change is currently behind a linked-on-or-after check (that is not iOS 16), to limit breakage from apps that may currently be calling `element.focus()` on iOS (without expecting a keyboard to show up).
Comment 7 Michal 2024-03-19 03:44:21 PDT
Guys, this is ridiculous. Whole world support this, only Safari doesn't. Please fix it.

You don't know how much unnecessary work it adds to people to get around this kind of thing.