Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Input autocomplete not working in WKWebview

Inputs with autocomplete enabled are working properly when opening in mobile Safari but not when loaded in a WKWebview (iOS 11.3). Is this a known limitation?

like image 899
tristanbbq Avatar asked Sep 17 '25 14:09

tristanbbq


1 Answers

I know I'm late to the party, but I had a surprisingly hard time finding a solution to such an old problem, so I wanted to share since this is still high on the Google results.

The autofill that I wanted was for the WKWebView to autocomplete a saved username and password for easy login. However, this could present a security risk to the user, so you have to add the "Associated Domains" entitlement to the iOS app that tells it which domains/subdomains it can trust, and you have to add a JSON file to the web site server's wwwroot/.well-known directory to prove that you control the site you are displaying in the WKWebView. Once that is done, then the username/password is autosuggested the same way that it is in Safari.

Here is the Apple documentation: https://developer.apple.com/documentation/xcode/supporting-associated-domains

To summarize the steps I took, in XCode, I went to the "Signing and Capabilities" tab in my app target, clicked the "+ Capability" button, added Associated Domains, and put entries in the newly created list for all of my subdomains:

webcredentials:example.com
webcredentials:www.example.com
webcredentials:othersubdomain.example.com

And then on my web server, I added a file to the .well-known directory called "apple-app-site-association" (no extension) with the following contents:

{
  "webcredentials": {
    "apps": [ "ABCDE12345.com.example.myapp" ]
  }
}

(where the format for the identifier is <Application Identifier Prefix>.<Bundle Identifier>). Then I browsed to https://www.example.com/.well-known/apple-app-site-association to make sure that the json was displayed in the browser.

Note: I use ASP.Net Core MVC, and the file WASN'T displayed in the browser since it doesn't use a recognized file extension. I found several methods for getting around that - I chose to add a file extension to the file and then use a rewrite rule in startup.cs so that Apple can find the file without supplying the extension in the request. You can find more on that at asp.net core - How to serve static file with no extension

like image 53
Dave Smash Avatar answered Sep 20 '25 04:09

Dave Smash