I am working on a JavaScript library for some data collection. I need to capture all click events, and want to traverse the event path looking for specific tags/ids/classes on click.
If I run the following code without the setTimeout, the event path always comes back with a single object in the array for Window. Add the setTimeout and the event path comes as expected.
window.addEventListener('click', function (event) {
// setTimeout with a 4ms delay to push to the end of the JS execution queue.
setTimeout(function() {
console.log(event.path);
}, 4);
});