From 84b450533e40d2eae9de32608bc22db084da7cc8 Mon Sep 17 00:00:00 2001 From: Max Franz Date: Wed, 1 Feb 2017 14:52:33 -0500 Subject: [PATCH] Make `touch*` event handlers explicitly `passive: false` in renderer #1702 - Test for passive event / options object for `addEventListener()` support - Supported browsers have all options set explicitly in the object - Unsupported browsers just use the `useCapture` boolean --- .../renderer/base/load-listeners.js | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/extensions/renderer/base/load-listeners.js b/src/extensions/renderer/base/load-listeners.js index d63b3baac1..1589b90f9b 100644 --- a/src/extensions/renderer/base/load-listeners.js +++ b/src/extensions/renderer/base/load-listeners.js @@ -17,8 +17,35 @@ BRp.registerBinding = function( target, event, handler, useCapture ){ BRp.binder = function( tgt ){ var r = this; - var on = function(){ - var args = arguments; + var tgtIsDom = tgt === window || tgt === document || tgt === document.body || is.domElement( tgt ); + + if( r.supportsPassiveEvents == null ){ + + // from https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md#feature-detection + var supportsPassive = false; + try { + var opts = Object.defineProperty( {}, 'passive', { + get: function(){ + supportsPassive = true; + } + } ); + + window.addEventListener( 'test', null, opts ); + } catch( err ){} + + r.supportsPassiveEvents = supportsPassive; + } + + var on = function( event, handler, useCapture ){ + var args = Array.prototype.slice.call( arguments ); + + if( tgtIsDom && r.supportsPassiveEvents ){ // replace useCapture w/ opts obj + args[2] = { + capture: useCapture != null ? useCapture : false, + passive: false, + once: false + }; + } r.bindings.push({ target: tgt,