Available in Chrome 46+ | View on GitHub | Browse Samples
The isTrusted read-only property of the Event
interface is a Boolean that is true when the event
was generated by a user action such as mouse click, and false when
the event was scripted or invoked via
dispatchEvent.
This new property is intended primarily for use by browser extensions, to determine if an event was dispatched by a script running in the main world or not.
var greenButton = document.querySelector('#greenButton');
var redButton = document.querySelector('#redButton');
greenButton.addEventListener('click', function(event) {
if (event.isTrusted) {
ChromeSamples.log('User clicked the green button. It is a trusted event.');
} else {
ChromeSamples.log('User did NOT click the green button.');
}
});
redButton.addEventListener('click', function() {
greenButton.click();
});