diff --git a/lib/utils/gestures.html b/lib/utils/gestures.html index c29c65cc53..738940f406 100644 --- a/lib/utils/gestures.html +++ b/lib/utils/gestures.html @@ -316,8 +316,9 @@ _findOriginalTarget: function(ev) { // shadowdom if (ev.composedPath) { - const target = /** @type {EventTarget} */(ev.composedPath()[0]); - return target; + const targets = /** @type {!Array} */(ev.composedPath()); + // It shouldn't be, but sometimes targets is empty (window on Safari). + return targets.length > 0 ? targets[0] : ev.target; } // shadydom return ev.target; diff --git a/test/unit/gestures.html b/test/unit/gestures.html index 31fb5d7882..4c8a92b4cb 100644 --- a/test/unit/gestures.html +++ b/test/unit/gestures.html @@ -550,6 +550,15 @@ document.dispatchEvent(new MouseEvent('click', { detail: 1, clientX: 100, bubbles: true, composed: true })); Polymer.Gestures.remove(document, 'tap', null); }); + + test('#5030', function() { + let count = 0; + const increment = function() { count++; }; + Polymer.Gestures.add(window, 'tap', increment); + window.dispatchEvent(new MouseEvent('click', {bubbles: true})); + assert.equal(count, 1); + Polymer.Gestures.remove(window, 'tap', increment); + }); });