-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chrome Autofill does not trigger change #7058
Comments
Currently the workaround i have is:
|
It works fine on Android, cannot test on iOS but there's a known issue with iOS Safari not emitting events when autocompleting, so, unfortunately, I'm not sure we can do something. |
I don't think this is something we can fix at the framework level, because it's buggy behavior in one specific browser (not firing |
Wrap elements in |
This issue is not unique to Vue and other front end frameworks have tried to tackle this as well The General ProblemAccording to this post on Detecting Browser Autofill from StackOverflow
Hack For WebKit browsersAccording to the MDN docs for the
Credit to the Klarna UI team for coming up with the solution here: :-webkit-autofill {
/* Expose a hook for JavaScript when auto fill is shown. */
/* JavaScript can capture 'animationstart' events */
animation-name: onAutoFillStart;
// Make the backgound color become yellow _really slowly_
transition: background-color 50000s ease-in-out 0s;
}
:not(:-webkit-autofill) {
/* Expose a hook for JS onAutoFillCancel */
/* JavaScript can capture 'animationstart' events */
animation-name: onAutoFillCancel;
} this.refs.input.addEventListener('animationstart', (e) => {
switch (e.animationName) {
case defaultStyles.onAutoFillStart:
return this.onAutoFillStart()
case defaultStyles.onAutoFillCancel:
return this.onAutoFillCancel()
}
}) Outside of that, you're probably going to have to resort to polling for changes, since we can't guarantee an event will fire. The library tbosch/autofill-event bills itself as "A polyfill to fire a change event when the browser auto fills form fields". |
@KyleMit Thanks for the details explanation. It's a-shame that we still don't have a proper consistent API to work with across browsers. |
You may add "name" attribute. It works for me in last Chrome ☮️ |
This trick works great, thanks! |
Confirm, It works! It looks like all fields that can be autofiled should have "name" attribute |
I have the same problem on Macos 10.13.3, chrome 70.0.3538.110.I find that just change when you click on any other non-input place, the change event will trigger, This seems to be triggered when the input's blur event fires.This is really weird. |
This not works for me,I do form validation when the blur event fires. When the blur event is triggered for the first time,the model of username and password was empty string.But when you click on any other non-input place, the change event will trigger,The model will get the autofilled value, This is really weird |
@yyx990803 why need this $nextTick()? |
For me it worked fine, if there was a single form field. With multiple fields, it wouldn't work. I had to have them wrapped in |
@rmaclean-ee You do not really understand what I mean,If you just click the login button to login, there is no problem.But if you bind blur event to the form field, when the blur event trigger you get the value, the value is empty, I think that Chrome remembers the password may be set the value to form fied when the blur event is triggered or after blur event is triggered. |
I wasn't responding to your point on the As I said, making sure it is wrapped in a form tag solved my issue and my v-model is correctly filled in now without the need for any workarounds. |
Has anyone got a working solution to this? I've tried a lot of the solutions proposed and still no luck |
@clem109 I totally have a working solution, but maybe you have hit something new? Can share some code of your page so maybe we can work out what specific aspect is not gelling |
I've omitted some aspects which were not necessary, I have this working now on iOS safari but iOS chrome it won't work at all... Thanks for the help @rmaclean-ee |
I know this issue has been closed for some time now, but just for the sake of documentation and future Googles: I'm having the same problem that @WormGirl detailed on Chrome 72.0.3626.121, MacOS 10.14.3. Clicking anywhere or calling something as simple as Interestingly enough, calling For reference, I have two inputs, email and password, and they both are wrapped in a I was able to get away with only CSS selectors (which work correctly), but this is definitely just a browser-specific bug. |
I've faced similar problem with autofill and v-model usage in Chrome browser on MacOS (Firefox is fine) and nothing mentioned above fixed the problem for me. I've been using The hack is instead of always binding value to
It looks dirty, feels dirty and it is actually dirty. But it works for me and it took a lot of time to come up with solution. Hopes it will help somebody. |
@PinkiNice what is b? it's not defined (trying to fix my bug here ) |
bug of chrome, not vue.
|
This is just like setTimeout. |
Based on facebook/react#1159, it looks like the input fields have the value before page load, so for vuetify (can easily be adapted for anything else), I added this code to my login dialog, and put refs on both text fields. Typescript w/ vue-property-decorator:@Component export default class extends Vue {
username = "";
password = "";
@Ref() readonly usernameBox!: Vue;
@Ref() readonly passwordBox!: Vue;
mounted() {
this.username = this.usernameBox.$el.querySelector("input")!.value;
this.password = this.passwordBox.$el.querySelector("input")!.value;
}
} Vanilla JS:export default {
data: () => ({
username: "",
password: "",
}),
mounted() {
this.username = this.$refs.usernameBox.$el.querySelector("input").value;
this.password = this.$refs.passwordBox.$el.querySelector("input").value;
}
} Edit:This approach works for material design inputs, preventing overlapping text, but the referenced issue also has an excellent comment by @thomasjulianstoelen describing why this behavior is, and how to fix it. Simply encasing things in form elements does not (usually) work. The form must have a submit button, or the user must hit enter within the form before the values become readable. I suggest reading the entire comment, but here's a summary: The reason password auto-fills can't be read is because it would be quite easy to setup a phishing attack, sending the user a malicious page, which can immediately read their passwords that the browser has auto-filled. To remedy this, you must wrap your auto-filled password boxes in a form and have a proper submit button. Once the form is submitted, the browser acknowledges this as user confirmation that the site can have access to their credentials, which then become readable. |
You could set autocomplete="off" attribute(HTML5), or record input value in url hash and update v-modal by it. |
The best way for me:
|
This is old Chrome bug, I just open https://bugs.chromium.org/p/chromium/issues/detail?id=1166619 for it. |
Seemingly still an issue, and after trying every possible combination it seems specific to IOS's native keychain password management + chromium browsers. No other combination has the issue, not IOS with safari, not chrome on android, nothing. |
Bug is still present. |
With this code, it works on both Chrome and Safari for me: <template>
<input
ref="input"
:value="value"
type="password"
@input="onInput"
@change="onInput"
/>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
const value = ref<string | null>(null);
function onInput(e: Event) {
// We should also fire this at the `@change` event on the input.
// Because `@input` does not always gets triggered when autofilling.
// This happens for example on iOS Safari when autofilling credentials from the keychain.
if (e.target instanceof HTMLInputElement && e.target.value) {
value.value = e.target.value;
} else {
value.value = '';
}
}
</script> It combines the following:
|
It is. Why is this closed? |
My understanding is that it was closed because it's an issue with the browser, not Vue, and that it likely won't get solved because there are security implications that come with exposing auto-filled login details to JS |
I'm curious what made you come to that conclusion. Because if you don't have access to the auto-filled value, how are you going to send it to the server? Sooner or later you will have to read the value in JS |
It's not that you never get the value. It's that it doesn't show up right away. I haven't run into this issue in a while so my memory is a little foggy, but if I remember correctly, the value is postponed until the user interacts with the page. If the user, for example, clicks the submit button, then the value is populated and the click event is fired in quick succession. I'm not at my computer right now though, so try it before taking my word for it. I don't remember there being anything functionally wrong when I came across this; the issue for me was that I was using material design, and the name of the textbook was overlapping the value until the user clicked "Login" since the event was postponed. It was just a design issue. Also, I don't remember what the rules are for interactions that count, but if you're still having issues, make sure that your button is an |
Some people indeed report that "interacting with the page" is enough for onChange/onInput to be triggered, but that's not what we observed (on Firefox - Chrome seems to work fine). |
Ok. This isn't an issue with Vue though; if you register the event handler yourself you'll get the same result. The issue lies within Firefox. I believe someone here opened a bug report on their tracker. Try checking there and see if anyone has offered a solution or status update. |
just wanted to share really cool and slicky solution https://stackoverflow.com/a/73633659/24207152 |
Version
2.5.3
Reproduction link
https://jsfiddle.net/n2kcp15b/
Steps to reproduce
What is expected?
update the v-model from what ever chrome autofilled
What is actually happening?
no update is happening
This only happens on Chrome on iOS (safari works fine). I also got reports it has the same issue on Chrome on Android but i didn't confirm.
This seems to be still an issue and i saw a few github issues that reported the same thing months ago but are now closed.
The text was updated successfully, but these errors were encountered: