Closed jessegreenberg closed 3 years ago
I had hoped that we could determine if the focus event had the trusted
flag to determine if it was from script of user input but trusted
is true even when calling focus()
from javascript.
I found this https://stackoverflow.com/questions/6727005/determine-what-triggered-focus-event, but the recommended originalEvent
is not standard and only works on firefox.
The documentation for isTrusted
The isTrusted read-only property of the Event interface is a boolean value that is true when the event was generated by a user action, and false when the event was created or modified by a script or dispatched via EventTarget.dispatchEvent().
So I am surprised that it is true in this case.
I am currently thinking we should only emit the userGestureEmitter
on 'input', 'change', 'click', 'keydown', 'keyup' since focusin
and focusout
could happen from javascript and still be considered "trusted".
This is the change I want to use:
I want to verify that the isTrusted
check works on all platforms and when using screen readers. To test this I will use each screen reader without tabbing into the sim and try moving a slider. userGestureEmitter
is currently only used by Sound.js and soundManager.js.
isTrusted
may not be true when fuzzing (creating fake input events) so maybe one risk with this is that we will not be able to test sounds with ?fuzzBoard
?
I tested these platforms with the above patch:
userGestureEmitter
from AT input.userGestureEmitter
from AT input.userGestureEmitter
from AT inputuserGestureEmitter
from AT input Its looking good to me!
Local aqua looks OK so I committed this change. @zepumph do you have other concerns with this or can you think of other things that we may need to test?
This makes total sense to me. Thanks for doing this. I completely agree. @jessegreenberg and I think that it isn't worth the risk to add the isTrusted check. Let's remove that.
In the above commit I removed the isTrusted
check and did some light spot checking. That was the last item for this issue, closing.
userGestureEmitter
is used to enable sound and maybe other features in response to legitimate user input. It is emitted on various input events including focus. But We call focus (on the ScreenView for screen reader reasons) on sim startup before any real user input. So it looks to scenery like theuserGestureEmitter
always emits on sim startup. Since it is always firing on startup I wouldn't be surprised if usages of userGestureEmitter are not working.