Through Javascript is it possible to detect synthetic clicks (the clicks that were not generated by human but instead was generated using JS or some other automation tool) ?
This is an old question but the accepted answer uses jQuery and I'm sure a lot of visitors here are looking for a vanilla JS solution. If you don't need to support IE, you can use Event.isTrusted
:
document.querySelector('a').onclick = function(event) {
if('isTrusted' in event) {
if(event.isTrusted === true) {
console.log('clicked on by a human');
} else if(event.isTrusted === false) {
console.log('click was triggered by a script');
}
}
};
https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted
In IE, all events are trusted except those created by createEvent
:
https://technet.microsoft.com/en-us/windows/ff974948(v=vs.60)