Chrome 52 onblur event works differently than it used to

6,100 views
Skip to first unread message

Shawn

unread,
Aug 23, 2016, 1:14:25 AM8/23/16
to Chromium-discuss
Our application uses onblur events to do client-side validation in javascript. When a field loses focus (onblur), a validation method is called. If the field is invalid, a simple alert message is shown and the focus is returned to the field.

Starting with Chrome 52, I get stuck in an infinite loop because the onblur event is firing every time I click the OK button on the alert message. It works correctly (the way it used to) in all other browsers, including Chrome 51.

Does anyone know what changed in Chrome 52, does Google plan to fix this, or is this an intentional change?

PhistucK

unread,
Aug 23, 2016, 1:18:51 AM8/23/16
to shawn....@gmail.com, Chromium-discuss
Your message was held in the moderation queue because it was your first post. That should not happen anymore, now that I approved you.

I tried simple cases -
data:text/html,<!doctype html><input type=text onblur=alert('')>
Or -
data:text/html,<!doctype html><form><input type="text"/><input type="submit"/></form><script>document.querySelector("input").addEventListener("blur", function () { alert('') });</script>
And they do not get stuck on an infinite loop.

If your case is more elaborate, please, share a URL that reproduces the issue so I could diagnose.


PhistucK

--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

Shawn

unread,
Aug 23, 2016, 11:22:12 AM8/23/16
to Chromium-discuss, shawn....@gmail.com
I was able to reproduce the problem with your simple example by clicking outside the browser window after placing focus on the text box. Then I get stuck in the infinite loop of the alert message. Our application is not available to the general public, it requires login credentials and unfortunately I cannot send you a URL. But I appreciate the help!


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

PhistucK

unread,
Aug 23, 2016, 12:11:30 PM8/23/16
to shawn....@gmail.com, Chromium-discuss
I see. I am not stuck in an infinite loop, though. I am clicking on something outside of Chrome, get the alert, click on OK, the field is still focused (as it should be), I click or tab outside of the field, I get an alert, I click on OK and that is it.
Do you see something else?

As an aside, switching from alert to an HTML based dialog will probably yield a more pleasant experience (it does not stop the event loop, so you can check whether the dialog is shown and just wait for the click). It has the added benefit of not disturbing the user with an application-modal alert box that blocks them from interacting with the browser completely.


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

Shawn

unread,
Aug 23, 2016, 1:36:06 PM8/23/16
to PhistucK, Chromium-discuss
Yes, I get different behavior. When I click outside the browser, the alert displays. I then click OK and the alert displays again. I click OK and it displays again. And on and on. I cannot get out of it without clicking the "prevent this page from creating additional dialogs." I'm on Chrome 52.0.2743.116 m

In my application, I don't need to click outside the browser window to see this behavior. I created a simple example inside my app by adding a new simple text input field with a simple onblur alert message and the behavior is the same. In Chrome 51 however, when I click OK on the alert, it goes away and returns the focus to the text box. Only Chrome 52 has this infinite alert behavior.

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

Shawn

unread,
Aug 23, 2016, 1:37:53 PM8/23/16
to Chromium-discuss, shawn....@gmail.com
Yes, I get different behavior. When I click outside the browser, the alert displays. I then click OK and the alert displays again. I click OK and it displays again. And on and on. I cannot get out of it without clicking the "prevent this page from creating additional dialogs." I'm on Chrome 52.0.2743.116 m

In my application, I don't need to click outside the browser window to see this behavior. I created a simple example inside my app by adding a new simple text input field with a simple onblur alert message and the behavior is the same. In Chrome 51 however, when I click OK on the alert, it goes away and returns the focus to the text box. Only Chrome 52 has this infinite alert behavior.



PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

Shawn

unread,
Aug 23, 2016, 1:42:19 PM8/23/16
to Chromium-discuss, shawn....@gmail.com
I will have to switch to DOM-based messaging. These alerts have been in place in this application for probably a decade or more. I inherited the maintenance on this beast. Anyway, there is a lot of code I must rewrite because of this Chrome 52 bug.

PhistucK

unread,
Aug 23, 2016, 2:59:24 PM8/23/16
to shawn....@gmail.com, Chromium-discuss
What platform are you on? I tried on Windows 7.


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

Shawn

unread,
Aug 23, 2016, 3:33:42 PM8/23/16
to Chromium-discuss, shawn....@gmail.com
I'm also on Windows 7.


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

PhistucK

unread,
Aug 23, 2016, 3:35:48 PM8/23/16
to shawn....@gmail.com, Chromium-discuss
You can search crbug.com for an existing issue and star it. If you cannot find one, file a new issue using the "New issue" link on the same page.
Please, do not add a "+1" or "Me too" or "Confirmed" (or similar) comment. It just wastes the time of Chrome engineers and sends unnecessary e-mails to all of the people who starred the issue.

You can reply with a link to the found or created issue and might get triaged (and fixed) faster.

Thank you.



PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

Наталья Картофелева

unread,
Oct 18, 2016, 1:40:38 AM10/18/16
to Chromium-discuss
We encountered the same issue with firing onblur every time the alert OK button is pressed. Did you manage to solve the problem?


вторник, 23 августа 2016 г., 12:14:25 UTC+7 пользователь Shawn написал:

Shawn

unread,
Oct 18, 2016, 11:26:06 AM10/18/16
to Chromium-discuss
My team solved the problem by switching from simple javascript alerts to dom-based messaging. The problem still exists in the Chrome browser.

PhistucK

unread,
Oct 18, 2016, 11:33:32 AM10/18/16
to natcon...@gmail.com, Chromium-discuss
You can search crbug.com for an existing issue and star it. If you cannot find one, file a new issue using the "New issue" link on the same page.
Please, do not add a "+1" or "Me too" or "Confirmed" (or similar) comment. It just wastes the time of Chrome engineers and sends unnecessary e-mails to all of the people who starred the issue.

You can reply with a link to the found or created issue and might get triaged (and fixed) faster.

Thank you.



PhistucK

--

Adrián Vaca

unread,
Oct 26, 2016, 1:39:23 AM10/26/16
to Chromium-discuss
Hi, I have the same problem in Chrome 54 and I solved in the following way:

- First add this utility function (Sorry for Spanish comments):

function showAlert(mensaje, control) {
// Respalda controlador del onblur
var eventoAnterior = control.onblur;
// Elimina controlador del onblur
control.onblur = null;
// Muestra mensaje
alert(mensaje);
// Coloca foco en el control y restaura controlador del onblur
setTimeout(function () {
control.focus();
control.onblur = eventoAnterior;
}, 0);
}

- Next, instead of calling alert call showAlert, note that "control" is a reference for the html input you want to validate:

showAlert('invalid data.', control);

PhistucK

unread,
Oct 26, 2016, 1:46:53 AM10/26/16
to adrian.fer...@gmail.com, Chromium-discuss
People, something might have unintentionally changed in the browser. If you do not report it at crbug.com, it will most probably stay buggy and you will need hacky workarounds such as the one Adrián mentioned.
Please, report it.


PhistucK

Eric

unread,
Nov 6, 2016, 2:32:49 AM11/6/16
to Chromium-discuss
Clicking outside the window still gives me the infinite loop problem. I was able to work around it by clearing and reassigning the value instead.

alert("Your input is invalid");
var temp = input_text.value;
input_text.value = '';
setTimeout(function() {
   input_text.focus();
   input_text.value = temp ;
 }, 0);

David Wieringa

unread,
Feb 12, 2017, 2:23:44 AM2/12/17
to Chromium-discuss, adrian.fer...@gmail.com
My team has stumbled on the same issue while maintaining a system developed for a client a year or two ago.

I found the bug reported here: https://bugs.chromium.org/p/chromium/issues/detail?id=666205   I have starred it.

I am seeing this in Chrome Version 56.0.2924.87 (64-bit) on OS X.  My teammate who reported it was also using Chrome on a MacBook Pro.

There is no issue when testing the same page with FireFox 51.0.1 (64-bit) or IE11 (running on Win7 via VirtualBox modern.ie image).

As others have mentioned, we are validating an input field with onblur.  When the validation fails an alert is shown and then focus is put back into the input field.  In Chrome now as soon as the user clicks OK, the alert is immediately presented again.  The user has no chance to alter or clear the text field to satisfy the validation.  In other browsers (and previously in Chrome), after clicking OK, the user can alter the content of the input field and the validation doesn't execute again until the user chooses to leave the field.

We stumbled on the issue in one place, but I'm sure it happens in many places.


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

Message has been deleted

E. de Juan

unread,
May 3, 2017, 2:49:34 AM5/3/17
to Chromium-discuss, tcg...@gmail.com
Muchas gracias Lo estoy probando y parece ir de lujo. Vaya tela con el chorme dándonos trabajo exra.

Por cierto, gracias por los comentarios en español ;).


Saludos.

Jandelson Oliveira

unread,
Jun 21, 2017, 2:34:52 AM6/21/17
to Chromium-discuss, shawn....@gmail.com

I am using 64-bit version 59.0.3071.104 (official version) and the error continues.

PhistucK

unread,
Jun 21, 2017, 2:38:09 AM6/21/17
to jandelson...@gmail.com, Chromium-discuss, shawn....@gmail.com
It is not planned to be fixed. You will have to work around it. See crbug.com/666205.


PhistucK

--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+unsubscribe@chromium.org.

jlm

unread,
Jun 21, 2017, 9:08:19 AM6/21/17
to Chromium-discuss, jandelson...@gmail.com, shawn....@gmail.com
It would be useful to review https://developers.google.com/web/updates/2017/03/dialogs-policy for better alternatives to the OS-level dialog boxes


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discu...@chromium.org.

Reply all
Reply to author
Forward
0 new messages