Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I turn on the webview autocomplete for an login form in Ionic's capacitor in iOS?

I want to know how to enable the autocomplete for a login form in Capacitor (or if it's possible). I'm using Ionic React. It works if access the page in Safari on iOS and even if you pin it to the home screen. But if you bundle the web app in Capacitor, the autocomplete is not there. Here's the code for the login form:

<form onSubmit={e => loginAndCloseModal({e, emailValue, passwordValue})}>
  <IonList>
    <IonItem>
      <IonLabel position="stacked">Email</IonLabel>
      <IonInput autocomplete="username" name="email" value={emailValue} onIonChange={e => setEmail(e.target.value)}></IonInput>
    </IonItem>
    <IonItem>
      <IonLabel position="stacked">Password</IonLabel>
      <IonInput autocomplete="current-password" name="password" type="password" value={passwordValue} onIonChange={e => setPassword(e.target.value)}></IonInput>
    </IonItem>
    { errorMessage &&
        <IonItem>
          <IonNote color="danger">{errorMessage}</IonNote>
        </IonItem> }
  </IonList>
  <IonButton class="login-button" expand="block" type="submit" disabled={authLoading}>Login</IonButton>
</form>

I've also tried setting autocomplete="on" as well and it didn't work. Apple's documentation recommends using the values posted above: https://developer.apple.com/documentation/security/password_autofill/enabling_password_autofill_on_an_html_input_element

Here's a screenshot of the login page on the web:

web version of login form

Here's a version of the login form in Capacitor:

capacitor version of login form

Notice the passwords option in the above the keyboard is gone. Why is that?

Here's the relevant dependencies of my project:

"@capacitor/cli": "^1.2.1",
"@capacitor/core": "^1.2.1",
"@capacitor/ios": "^1.2.1",
"@ionic/react": "^4.11.2",
"@ionic/react-router": "^4.11.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",

I'm using iOS version 12.4.2

EDIT:

I've done some more research. There this documentation from Apple. The relevant section is this:

Enable Password AutoFill

Password AutoFill uses heuristics to determine when the user logs in or creates new passwords, and automatically provides the password QuickType bar. These heuristics give users some Password AutoFill support in most apps, even if those apps haven’t been updated to support AutoFill. However, to provide the best user experience and ensure your app fully supports Password AutoFill, perform the following steps:

  1. Set up your app’s associated domains. To learn how to set up your app’s associated domains, see Setting Up an App’s Associated Domains.

  2. Set the correct AutoFill type on relevant text fields. For an iOS app, see Enabling Password AutoFill on a Text Input View. For a web app, see Enabling Password AutoFill on an HTML Input Element.

I did 2 from above when I first asked this question, but not 1. However after doing number 1 it's still not working.

Here's some more relevant documentation from Apple.

like image 408
CovertIII Avatar asked Oct 23 '19 21:10

CovertIII


People also ask

How to create login and registration form in ionic framework?

Open the register.ts (contain the logic part of app which is basically in typescript) file and write these code there…. So in the end, we learn “ Creating Login and Registration Form in Ionic “, how to navigate between pages, add alert box and loading, if you have any doubt please comment.

How do I enable or disable autocomplete on my website?

Select Internet Options from the drop-down menu. Under the Content tab, in the Autocomplete section, click the Settings button. In this window, you can select the fields you'd like to store autocomplete data by using the check boxes. This action turns Autocomplete On or Off based on what boxes are checked.

How to turn off autocomplete on safari?

Select from the menu bar in the top-left corner of the screen. In the drop-down menu that appears, select Preferences. At the top of the window that appears, click the Search tab, and then uncheck the box next to Include search engine suggestions. From now on, Safari no longer stores or offers new autocomplete suggestions.

How do I Turn on auto complete in Internet Explorer?

In the search box on the taskbar, type Internet Explorer and then choose it from the results. Select Tools > Internet options. In the Content tab, select Settings under the AutoComplete section. Select the check boxes for the options you want AutoComplete to use, then choose OK.


2 Answers

I found a workaround here: https://github.com/ionic-team/ionic/issues/19478#issuecomment-559081576

Basically don't wrap any of your input fields in an ion-item tag, use div instead (for example).

The corresponding WebKit bug report is this: https://bugs.webkit.org/show_bug.cgi?id=203299

like image 80
Moritz Avatar answered Sep 30 '22 08:09

Moritz


  1. First, log into the Apple Developer site. Navigate to the “Certificates, Identifiers, & Profiles” section and select your app’s identifier. Note the App ID prefix and Bundle ID, and under Capabilities, toggle “Associated Domains” then save.

  2. Then, create a file on your web server called apple-app-site-association. This file will be configured in JSON format, but it is not allowed to have a .json or any other extension.

  3. Paste the following content inside the file and edit the marked places.

    Replace XXXXXXXXXX with the App ID prefix and com.example with the Bundle ID of the app.

    {
      "webcredentials": {
        "apps": [
          "XXXXXXXXXX.com.example" // Replace this
        ]
      },
      "applinks": {
        "apps": [], // needs to be empty
        "details": [
          {
            "appID": "XXXXXXXXXX.com.example", // This too
            "paths": [
              "*"
            ]
          }
        ]
      }
    }
    
  4. After that, make sure this file is accessible via the route https://example.com/.well-known/apple-app-site-association.

  5. Also make sure that your server uses https

  6. It is also necessary to specify the content type for this file. It needs to be application/pkcs7-mime. This can be done, for example, using Website Headers. At the hosting provider Render.com it looks like this, for example:

Example Website Header configuration on render.com

  • Request path: /.well-known/apple-app-site-association
  • Header name: Content-Type
  • Header value; application/pkcs7-mime
  1. Now you have to open the ios/ folder in XCode. You can do this manually or by using the command npx cap open ios. There you click on App in the left side bar and then again on App under Targets. Then select the Signing & Capabilities tab.
  2. Add a new Associated Domains Capability and then add the domain applinks:example.com for Deep Link support and webcredentials:example.com for auto-populating passwords. Replace example.com with the domain name of your website.

Edit: I have also added the Autofill Credential Provider capability.

If nothing has changed, then everything should work now. Otherwise, here are a few helpful links that have helped me:

  • Capacitor – Deep Linking with Universal and App Links
  • Setting up iOS Universal Links
  • How to Setup Universal Links in Ionic (iOS & Android)
  • Enabling Password AutoFill on an HTML Input Element
  • Universal Link Validator
like image 28
Valentin Gavran Avatar answered Sep 30 '22 10:09

Valentin Gavran