android / input-samples

Multiple samples showing the best practices in input on Android.
Apache License 2.0
288 stars 265 forks source link

WebView sample doesn't work #26

Open wizche opened 6 years ago

wizche commented 6 years ago

The WebView example doesn't trigger any OnFill requests. Tested on Pixel C (Android 8.0.0 - OPR6.170623.010). Build tool version: 26.0.1

Are WebViews actually supported? Any timeline about Chrome Mobile support?

the-felipeal commented 6 years ago

WebView requires Chrome 61 or later - could you please confirm what version do you have?

wizche commented 6 years ago

@the-felipeal thanks a lot, auto-update was disabled :) Updating chrome solved the issue. Can you disclose any timeline for chrome autofill service support?

the-felipeal commented 6 years ago

We're working on it...

pocmo commented 6 years ago

I've been testing the WebView sample on an emulator (API 26) and a Pixel XL with 8.1.0 beta. In both cases I do not get any autofill suggestions inside the WebView. All other examples seem to work. Chrome 62 is installed on both devices.

DougSig commented 6 years ago

I cannot reproduce what you are describing (though I've only tested on a Nexus 5X running 8.0.0). Can you verify the following: 1) Search in settings for "WebView implementation". Verify the version is 62 as you said. 2) Make sure you're saving autofill data before expecting suggestions. 3) If the issue is that the Save UI is not coming up for the webview, make sure you fill in all fields on the page before submitting the form. (this applies to all pages, not just the WebView).

pocmo commented 6 years ago

Yeah, it's 62. I also tried 63 (Beta) and 64 (Dev).

Weirdly it just started to make autofill suggestions for the "work email" and "shipping address1" fields. But not for data I entered. It just picked up my actual work email and address from somewhere else.

All other fields never get suggestions.

If the issue is that the Save UI is not coming up for the webview, make sure you fill in all fields on the page before submitting the form. (this applies to all pages, not just the WebView).

I saw the save UI popup in one of the other samples. But never for the WebView.

DougSig commented 6 years ago

You need to set the default auto fill service to the sample service (see readme).

DougSig commented 6 years ago

The latest change makes the client app and the service separate apps, so you have to install both "Application" and "afservice" from Android Studio before you can set the sample service as your default service. This isn't reflected in the readme yet, but will soon.

pocmo commented 6 years ago

Thanks!

With the sample service I can get the form inside the WebView filled with "fake autofill data". It does not save any new data I enter though (might not be part of this example?).

I'm still a bit confused that this does not work with the default Google autofill service. This means this is completely up to the service implementation and it's not in my control?

the-felipeal commented 6 years ago

I'm still a bit confused that this does not work with the default Google autofill service.

Filling WebView is more complicated because the service needs to securely associate the app with the domain of the HTML page. The suggested way to verify that is by using Digital Asset Links, whose validation would fail for the sample app; when it fails, it's up to the service to either not autofill or provide an UI warning the user (see https://developer.android.com/reference/android/service/autofill/AutofillService.html#WebSecurity); my guess is that Autofill with Google is ignoring it in this case, but I don't know for sure.

This means this is completely up to the service implementation and it's not in my control?

Yes, whether or not it will works depend on the service, and you don't have control over it. But that's why we provide a reference implementation - if your app works with the reference implementation, it should work with other services as well.

If your app works with the reference service but doesn't work with another services, the problem is in that service - in this particular case, I will file an internal bug against Autofill with Google, as it should work.

DougSig commented 6 years ago

It does not save any new data I enter though (might not be part of this example?).

Are you triggering the autofill save UI when you press submit? You need to modify all EditTexts on the page to trigger it. Also, autofill data saved from the "Sample Login Using EditTexts" Activity, for example, should show in the lists of datasets when tapping on the username or password fields in the WebView.

RiRomain commented 6 years ago

Are you triggering the autofill save UI when you press submit? You need to modify all EditTexts on the page to trigger it

How to achieve that? I tried calling mAutofillManager.commit(); but it simply doesn't record the login data.

(the lists of datasets is correctly displayed when I tapp on my username or password edit field).

DougSig commented 6 years ago

Are you referring to the sample app or your own app?

DougSig commented 6 years ago

You don’t need to call autofillManager.commit(), WebView handles that internally.

RiRomain commented 6 years ago

I'm referring to my own app, the login is actually handle prior to opening the webview. Is there another way of telling the autofillManager that the form is complete and should be saved?

the-felipeal commented 6 years ago

You shouldn't need to call AutofillManager.commit() - WebView calls that method when it detects that the form is submitted. If it's not called, it's a WebView bug and/or limitation (some HTML pages have very complex JavaScript code designed to disable autofill).

Another possibility is that the autofill context is committed, but the autofill service does not know how to autofill your app. In particular, the autofill service from the services only "understand" standard autofill hints, which in the case of WebView should be the autocomplete tags with the values specified at https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#autofilling-form-controls%3A-the-autocomplete-attribute (such as "username" and "current-password") - does your HTML code set these attributes?

the-felipeal commented 6 years ago

Also, you can check if commit() was called by running:

adb shell cmd autofill set log_level verbose

Then watch for AutofillManager logs. For example, when I tap Login in the WebView Sample, I can see the following logged:

03-26 22:44:00.504 5344 5344 V AutofillManager: finishSessionLocked(): STATE_ACTIVE

Notice that the sample app requires all fields to be set to trigger the Save UI; if you change say just username and password, you should see a message such this:

03-26 22:47:50.778 2137 3012 D AutofillSession: showSaveLocked(): with no changes, comes no responsibilities.allRequiredAreNotNull=false, atLeastOneChanged=true

arunp1990 commented 6 years ago

Hi, I found an issue with Autofill Google. Once I click "No Thanks" to deny saving usename+password, I can't enable this option of saving form data again. I am not sure if this is supported in Google Chrome itself. But, an official input regarding this will be helpful. I saw that an internal bug was filed against Autofill with Google by @the-felipeal . Could you please let me know how I can file a bug or Enhancement request for this? Is any particular Google forum or google bug tracking website for this?

The above issue was encountered by me in a mobile app which uses WebView. This was done in emulator. I then tried logging in with Chrome mobile browser in the same emulator. This time, I logged in with a different user and saved the password. But, when I try to login in the mobile app (which has webview), the prompt to auto-fill is not coming. I tried long press on username input field, paste and autofill options came up. I clicked on Auto fill. It took me to "Saved passwords" screen. But, the password which got saved in Chrome was not present there. I even tried re-installing the app. The prompt to save password still does not come when I try to login.

the-felipeal commented 6 years ago

@arunp1990 , when you tap No, Thanks in the opt-in dialog, Google Autofill [disables itself](https://developer.android.com/reference/android/view/autofill/AutofillManager.html#disableAutofillServices()) - you'd need to explicitly set it again, through Settings -> "search for autofill" -> Autofill Service.

simonfongnt commented 3 years ago

cannot see onFillRequest triggered in Chrome 85, Android 10. But it can be triggered in Firefox.